Home · Guides · Playwright browser

How to give your AI agent a cloud browser with Playwright

What this tutorial is

Search for a Playwright sandbox, how to run Playwright in the cloud for AI agents, or how to connect Playwright over CDP, and you will mostly find laptop recipes: a local Chromium, Docker Compose, or a CI job that launches a headless browser. This page is the Impello path: an isolated Linux microVM in Germany or Finland that your TypeScript or Python code starts with Sandbox.create('browser'), then attaches Playwright to over the Chrome DevTools Protocol.

It is a step-by-step tutorial, not a comparison. The product page for this use case is AI agent browser automation. The SDK examples below are the same calls as /docs/browser. Coding agents that need a CLI rather than a browser are on coding agents.

A Playwright sandbox is not a desktop computer-use stack

Two different products get searched as a computer use sandbox. Mixing them up is how people boot a whole desktop when they only needed Chromium, or the other way around.

Impello's browser template is a headful Chromium an agent drives over CDP. A person can watch or take over through noVNC. That is the computer-use job for a lot of agents: operate a real browser. It is not a screenshot-and-mouse desktop. If you want a whole Linux desktop over noVNC, that is the omarchy template. The claude template is Claude Code, not a browser.

Impello browserImpello omarchy
What you getHeadful Chromium, fingerprint per profile, CDP on 9222, noVNC on 6080Arch Linux desktop (Omarchy shell on sway) over noVNC on 6080
How an agent drives itPlaywright or Puppeteer over CDP. connectOverCDP, never launch()The desktop itself, watched over noVNC
Size and hour2 vCPU / 4 GB, $0.018/h, fits the trial4 vCPU / 8 GB, $0.036/h, needs a plan

From /browser and templates. This tutorial uses the browser template and Playwright's CDP connect API.

1. Before you start

You need an account, a key, then two installs.

  1. An Impello account. Sign up. The 7-day trial needs a card, one trial per card. Sandboxes are billed against team credit; a team with no plan cannot create one. See the quickstart.
  2. An Impello API key, in IMPELLO_API_KEY. Create one at dashboard.impello.ai/keys. Both SDKs read that name. Details: API keys.

TypeScript

npm install @impello/sdk playwright

Python

pip install impello playwright

@impello/sdk needs Node 20.18.1 or later on the 20 line, or Node 22 or later. impello needs Python 3.10 or later. Both SDKs also read IMPELLO_API_KEY from the environment. You install the Playwright library so you can import chromium; you do not launch a local browser.

export IMPELLO_API_KEY=imp_...

2. Create a sandbox from the browser template

Pass browser to Sandbox.create. That name boots the default template: headful fingerprint-chromium, an open-source build of ungoogled-chromium, pinned to version 150, on an Xvfb display with openbox. Size is 2 vCPU / 4 GB. The working directory is /home/user. Port 9222 is CDP. Port 6080 is a live view of the screen in noVNC.

There is no getCdpUrl helper. The host for a port is getHost(port) (get_host in Python). You supply the scheme. The sandbox itself starts in 1–3 seconds, like every other Impello box. Chromium starts on the first CDP request, so that first connection then takes about 5 to 10 seconds longer than the ones after it.

Set a sandbox timeout. The default is 5 minutes (timeoutMs: 300_000 in TypeScript, timeout: 300 in Python) and activity does not move it. A browsing session is usually longer than that. The snippets below use 30 minutes, the same value as the browser docs.

TypeScript

import { Sandbox } from '@impello/sdk'

const sandbox = await Sandbox.create('browser', { timeoutMs: 1_800_000 })
const cdp = `https://${sandbox.getHost(9222)}`
console.log(cdp)

Python

from impello import Sandbox

sandbox = Sandbox.create("browser", timeout=1800)
cdp = f"https://{sandbox.get_host(9222)}"
print(cdp)

3. Connect Playwright over CDP

Playwright attaches with chromium.connectOverCDP in TypeScript and chromium.connect_over_cdp in Python. Both take a CDP WebSocket endpoint or HTTP URL. Impello's is the HTTPS address of port 9222. Connecting over CDP is Chromium-only; Playwright says so on those pages.

Connect, never launch. chromium.launch() starts a second, local browser with automation switches turned on, and a page can see them. connectOverCDP attaches to the one already running in the sandbox.

Use the browser's existing context, browser.contexts()[0] (browser.contexts[0] in Python). It is the profile on disk, with its fingerprint, cookies and logins. A context you make with newContext() (new_context()) is a fresh incognito-style context that keeps nothing.

TypeScript

import { Sandbox } from '@impello/sdk'
import { chromium } from 'playwright'

const sandbox = await Sandbox.create('browser', { timeoutMs: 1_800_000 })

const browser = await chromium.connectOverCDP(
  `https://${sandbox.getHost(9222)}`
)
const context = browser.contexts()[0]
const page = context.pages()[0] ?? (await context.newPage())

await page.goto('https://example.com')
console.log(await page.title())

Python

from impello import Sandbox
from playwright.sync_api import sync_playwright

sandbox = Sandbox.create("browser", timeout=1800)

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(f"https://{sandbox.get_host(9222)}")
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()

    page.goto("https://example.com")
    print(page.title())

Puppeteer talks to the same CDP endpoint; so does anything else that speaks the protocol. The URL is the HTTPS address of port 9222. Its /json/version answers with a wss:// WebSocket address on the same host, which is what Playwright reads. A client that wants the WebSocket address directly can use wss://<host>/ with no path.

With network: { allowPublicTraffic: false } (network={"allow_public_traffic": False} in Python) the CDP and live-view ports stop answering callers without the sandbox's traffic access token. Send the token in the impello-traffic-access-token header. Playwright sends the headers you give connectOverCDP on both the HTTP request and the WebSocket. Without the header, the port answers 403.

TypeScript

import { Sandbox } from '@impello/sdk'
import { chromium } from 'playwright'

const sandbox = await Sandbox.create('browser', {
  network: { allowPublicTraffic: false },
})

const token = sandbox.trafficAccessToken
if (!token) throw new Error('no traffic access token')

const browser = await chromium.connectOverCDP(
  `https://${sandbox.getHost(9222)}`,
  { headers: { 'impello-traffic-access-token': token } }
)

Python

from impello import Sandbox
from playwright.sync_api import sync_playwright

sandbox = Sandbox.create("browser", network={"allow_public_traffic": False})

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(
        f"https://{sandbox.get_host(9222)}",
        headers={"impello-traffic-access-token": sandbox.traffic_access_token},
    )

4. Watch and take over via noVNC

The screen is served by noVNC at /vnc.html on port 6080. There is no getVncUrl helper. Open the URL in a browser tab to watch the agent, or click into it to take over: the keyboard and mouse are shared with the agent. This is the same Chromium the agent is driving over CDP, not a second copy.

TypeScript

console.log(
  `https://${sandbox.getHost(6080)}/vnc.html?autoconnect=true&resize=scale`
)

Python

print(
    f"https://{sandbox.get_host(6080)}/vnc.html?autoconnect=true&resize=scale"
)

The live view takes the traffic-access token as a header too, so a browser tab cannot open the live view of a private sandbox on its own. Put a proxy you control in front of it that adds the header, or keep the sandbox public only while you watch.

5. Pause to keep cookies and logins

A profile is a directory under ~/.browser/profiles/, default unless you name another. It holds the cookies, local storage, history and logins, and the fingerprint seed. The disk survives pause, so a paused sandbox comes back signed in where you left it.

Leave the sandbox running and Impello meters the reserved vCPUs the whole time: $0.018 an hour at 2 vCPU, idle or not. Call pause() and it costs nothing.

By default pause snapshots memory and disk, so processes and open files survive. Resume with Sandbox.connect(sandboxId); that starts a fresh timeout (5 minutes unless you pass one). There is no method named resume. After resume, connect Playwright over CDP again: the old WebSocket is gone. Pass keepMemory: false (keep_memory=False) to persist only the filesystem — resume then cold-boots from disk, and Chromium starts on the next CDP request.

TypeScript

import { Sandbox } from '@impello/sdk'
import { chromium } from 'playwright'

const sandboxId = sandbox.sandboxId
await sandbox.pause()

const resumed = await Sandbox.connect(sandboxId, {
  timeoutMs: 1_800_000,
})
const browser = await chromium.connectOverCDP(
  `https://${resumed.getHost(9222)}`
)

Python

from impello import Sandbox
from playwright.sync_api import sync_playwright

sandbox_id = sandbox.sandbox_id
sandbox.pause()

resumed = Sandbox.connect(sandbox_id, timeout=1800)
with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(
        f"https://{resumed.get_host(9222)}"
    )

A sandbox that has sat paused for 14 days is deleted. The clock restarts every time you pause. Paused sandboxes do not count against concurrency, and there is no cap on how many you keep paused. Pause, resume and snapshots. Inside the sandbox, the browser command can restart Chromium onto another profile, a proxy, or a timezone; those flags are on /docs/browser.

6. Kill the sandbox

kill() destroys the sandbox. It returns true when it killed one and false if the sandbox was not found, so killing twice is safe. Pause keeps the box; kill does not.

TypeScript

await sandbox.kill()

await Sandbox.kill(sandbox.sandboxId)

Python

sandbox.kill()

Sandbox.kill(sandbox.sandbox_id)

Put it in a finally (or Python with Sandbox.create(…), which kills on exit) so a failed session does not leave a running box on the meter.

Pricing and honest limits

There is no special browser SKU. Every plan meters at $0.0000025 per vCPU-second. The browser template is 2 vCPU, so an hour is $0.018. RAM, disk, egress, snapshots and paused time are not billed. Only running time, from start or resume until pause or kill.

A 7-day trial with $5 of credit (a card is required), then $20 / $100 / $500 a month, each plan returning its price as monthly credit. Plan credit expires at the end of the month; credit packs do not, while the account is open. The template is 2 vCPU / 4 GB, so it fits the trial's ceiling. omarchy is 4 vCPU / 8 GB at $0.036 an hour and needs a plan.

The same trade-offs we print everywhere else apply here:

  • The browser does not solve CAPTCHAs and is not a way around a site's terms. A fingerprint per profile, a matching timezone and a headful display remove the differences that make an automated browser look unlike a person's; they do not change what the agent does on the page.
  • The browser renders on the CPU, with no GPU, so pages heavy on WebGL or video are slower than on a desktop.
  • Starts take 1–3 seconds, not the ~80–200 ms some others advertise. The first CDP connection then takes about 5 to 10 seconds longer because Chromium starts on that request.
  • Burst is modest: 5 starts a minute and 2 concurrent sandboxes on the trial, 65 a minute and 300 concurrent on the $500 plan. A create over the cap is refused, not queued.
  • A sandbox may run for 1 hour on the trial, 12 hours on $20, or 24 hours on $100 and $500. At the deadline the sandbox is killed unless you set lifecycle: { onTimeout: 'pause' } at create time.
  • A paused sandbox is kept 14 days, then deleted.
  • Compute is EU only, in Germany and Finland. There is no region option, no Windows, no macOS, no SLA, no status page and no support channel. The service is in early access.
  • We do not ship a CLI, volumes, a secrets store, or a desktop / code-interpreter client package. Impello is sold to businesses.

FAQ

How do I give an AI agent a cloud browser with Playwright?

Create a sandbox from Impello's browser template, then attach Playwright with chromium.connectOverCDP (connect_over_cdp in Python) to the HTTPS address of port 9222. Anyone can sign up for a 7-day trial.

How do I connect Playwright over CDP to an Impello sandbox?

There is no getCdpUrl helper. Call sandbox.getHost(9222) (get_host in Python) and pass that host as an HTTPS URL to chromium.connectOverCDP. Connect, never launch: launch() starts a second, local browser. Playwright documents connectOverCDP as Chromium-only.

Is this a computer use sandbox?

It is a sandbox an agent uses to operate a real browser, which is the computer-use job for a lot of agents. It is not a screenshot-and-mouse desktop. If you want a whole Linux desktop over noVNC, that is the omarchy template. The claude template is Claude Code, not a browser.

Do cookies and logins survive pause?

Yes. Each profile is a directory on disk under ~/.browser/profiles/. It holds cookies, local storage, history, logins, and the fingerprint seed. Pause keeps the disk, so a paused sandbox comes back signed in where you left it. Resume with Sandbox.connect(sandboxId), then connect Playwright again. A sandbox paused for 14 days is deleted. Pause costs $0.

Can a person watch or take over the browser in noVNC?

Yes. Open /vnc.html on port 6080. There is no getVncUrl helper: build the HTTPS URL from sandbox.getHost(6080) with path /vnc.html?autoconnect=true&resize=scale. The keyboard and mouse are shared with the agent. With the default public traffic setting, anyone who has the URL can drive and watch, including every page the browser is signed in to.

How much does a Playwright sandbox cost on Impello?

The browser template is billed like every other 2 vCPU sandbox: $0.018 an hour. RAM, disk and egress are not billed. Pause is $0. The template is 2 vCPU / 4 GB, so it fits the free trial's ceiling.

Sign up

Anyone can sign up. If a Playwright sandbox in the cloud — a headful Chromium your AI agent can drive over CDP, with noVNC takeover and a profile that survives pause — is what you need, start a 7-day trial.

The product page for this use case is browser. Code, not copy: browser docs, network, timeouts, pause and snapshots. Coding agents that need a CLI: coding agents. More guides: guides. How to choose among providers: best AI agent sandboxes.

Sources

Impello facts are from this site's docs and code. Playwright API names are from Playwright's own docs, read for this page. No competitor list rate is quoted.