Skip to content

Browser

sandbox.browser drives headless Chromium in a sandbox from the browser template. It reads a page as an accessibility tree: a short outline in which every control has a ref (e12) that click and type take. An interactive page costs a few hundred tokens this way, where a screenshot costs an image’s worth on every step.

import re
from svm import Sandbox
def ref_of(snapshot: str, role: str) -> str:
"""The ref of the first element with this role, as in '- searchbox "Search" [ref=e12]'."""
return re.search(rf"{role}\b[^\n]*\[ref=(e\d+)\]", snapshot).group(1)
browser_server = [{"name": "browser", "catalog_id": "browser"}]
with Sandbox.create(template="browser", mcp_servers=browser_server) as sandbox:
browser = sandbox.browser
page = browser.navigate("https://www.wikipedia.org")
print(page.text[:400]) # the page as an accessibility tree
snapshot = browser.snapshot()
browser.type(ref_of(snapshot.text, "searchbox"), "Firecracker microVM", submit=True)
browser.click(ref_of(browser.snapshot().text, "link"))
with open("page.png", "wb") as f:
f.write(browser.screenshot())
Method What it does
navigate(url), back() Move, and return the snapshot after the move
snapshot(max_chars=) The accessibility tree, cut at 24,000 characters
click(ref), type(ref, text, submit=), press(key) Act on a ref from the latest snapshot
wait_for(text=, gone=, seconds=) Wait for the page to show or lose some text
screenshot(full_page=) PNG bytes, only when you ask
call(tool, args), tools() Any tool the browser server offers

The same Chromium serves the DevTools protocol inside the sandbox at browser.cdp_url. The browser-use library is installed in the template and attaches there.