Skip to content

Use a web browser in a sandbox from your code or an agent, and watch it over VNC.

browser lets your code, or an agent, use a web browser in a sandbox: open pages, read what is on them, click, type, and take screenshots. It brings the browser with it, so the image needs nothing for it. This guide acts on example.com, then searches Wikipedia in a window you watch.

Open a page and act on it

The commands share one browser, with its tabs and sign-ins, until browser close. snapshot -i lists what on the page can be clicked or typed into, each with a ref such as @e2 for the next command to act on.

sandbox = await client.create_sandbox("alpine:latest", abins=["browser"])
async def browser(*args):
await sandbox.exec(["browser", *args]).complete(print=True)
await browser("open", "https://example.com")
await browser("snapshot", "-i")
await browser("click", "@e1")
await browser("get", "url")
await browser("close")

A snapshot reads as:

Output
- heading "Example Domain" [level=1, ref=e1]
- link "Learn more" [ref=e2]

Take a snapshot again after the page changes. Pages outside the sandbox need its network on, as it is by default. browser --help lists every command, and an agent learns them from /abin/skills/browser/SKILL.md.

Watch it in a window

--headed shows the browser in a window on a display screen, where a person watches it over VNC and can take over, such as to sign in. This opens Wikipedia in a window and searches it for meerkats:

from virtx import PortForwarder, Stdout
sandbox = await client.create_sandbox(
"alpine:latest",
abins=["browser", "display"],
ports=[5900]
)
async for entry in sandbox.exec(
["display", "run", "--size", "1280x800", "--password", "secret"]
):
if isinstance(entry.entry, Stdout) and entry.entry.line == "ready":
break
for cmd in [
"DISPLAY=:99 browser --headed --args '--window-position=0,0,--window-size=1280,800' open https://en.wikipedia.org",
"browser fill 'input[name=search]' meerkat",
"browser press Enter",
"browser wait --url '**/wiki/Meerkat'",
]:
await sandbox.exec(["sh", "-c", cmd]).complete(print=True)
with await PortForwarder.open(sandbox, 5900) as forwarder:
print(f"vnc://{forwarder.local}")
input("Press Enter to stop watching")

The window, in a VNC viewer, as the commands run:

How long a browser lasts

A browser closes once its sandbox has been idle for a few minutes. To keep a sign-in, save it and load it in the next browser:

browser state save /root/state.json
browser --state /root/state.json open https://example.com/account

Saved in a volume, it carries over to another sandbox too.