Skip to main content
BrowserBox does not run your automation script inside the box. It places the browser inside the box and exposes a WebSocket endpoint; your script runs on the host and drives the browser remotely, so untrusted page JavaScript, downloads, and cookies never reach your machine.

Prerequisites

  • A working BoxLite install (Python boxlite or Node @boxlite-ai/boxlite) and a machine with hardware virtualization — see Installation.
  • Install the browser-driver client (used to connect from the host):
    • Python: pip install "playwright==1.58.0" (you do not need playwright install; the browser lives in the sandbox)
    • Node: npm install [email protected] (an optional peer dependency of @boxlite-ai/boxlite)
    • The client version must match the Playwright Server version inside the sandbox (1.58.0). If you install an unpinned pip install playwright that resolves to a newer version (for example 1.60.0), connect() receives 428 Precondition Required, reports Playwright version mismatch, and fails. Pin 1.58.0 explicitly.
  • The first run pulls the image mcr.microsoft.com/playwright:v1.58.0-jammy (several GB); this requires network access and takes a while.

Quick Example (happy path)

The snippet below starts an isolated Chromium from the host, navigates to example.com, and prints the title. It is ready to copy and run.
@boxlite-ai/boxlite is an ESM-only package, so the Node example uses ESM syntax.

Two connection modes

BrowserBox offers two mutually exclusive ways to connect; a single instance can use only one of them:
A single instance cannot use both playwright_endpoint() and endpoint() — both bind host port 3000. If you need both modes, start a separate BrowserBox for each.
Convenience helper connect(): returns an already-connected Playwright Browser object directly (it uses Playwright Server mode internally), saving you the manual connect(ws) step.

Parameters & Returns

BrowserBoxOptions (Python, dataclass)

Construct as BrowserBox(options=BrowserBoxOptions(...)). BrowserBox also accepts extra **kwargs that are passed through to the underlying SimpleBox (such as volumes, env, ports, name, auto_remove).

Node options (BrowserBoxOptions, object)

new BrowserBox({ ... }) inherits from SimpleBoxOptions (Omit<SimpleBoxOptions, "image" | "cpus" | "memoryMib"> — that is, image is removed, and cpus / memoryMib are re-declared as optional fields with browser defaults) and adds browser-specific fields:

Methods / return values

Image and version (fixed): the default image is mcr.microsoft.com/playwright:v1.58.0-jammy, corresponding to Playwright 1.58.0. The client used to connect from the host must also be 1.58.0 (a mismatched client is rejected by the server; see Troubleshooting).

Advanced: screenshots and form interaction

Once you have the endpoint, everything else is standard Playwright API (running on the host). The example below shows navigation, a screenshot, and filling a form, with the screenshot saved on the host (not inside the sandbox).

Parallel / cross-browser (each on its own port)

When launching multiple browsers in parallel, you must assign a different host port to each instance, otherwise the ports collide.

Troubleshooting