What you can do
- Automate a real Chromium browser with Playwright or any tool that connects over .
- Watch or take over a live run through
viewer_urlwhen the agent gets stuck on login, file upload, or a surprising page state. - Connect computer-use agents through
display_url, a address for screen-based tools. - Keep browser state separate with
profile_id, so cookies and local storage belong to the sandbox profile instead of your host browser. - Collect evidence with screenshots, downloads, logs, and optional video recordings.
Choose a mode
Headless browser mode has the smallest browser surface because it only exposes the browser automation endpoint. Visible browser mode starts the live viewer and VNC display as well. Use desktop mode when your agent needs the whole desktop, not just Chromium.
Start a browser sandbox
- Python
- CLI
browser_sandbox.py
cdp_url is for automation libraries. viewer_url opens in your browser so a person can watch or interact with the run. display_url is for VNC-compatible tools and computer-use agents.
Automate with Playwright
Useconnect_playwright() when you want Python code to drive the sandbox browser.
playwright_browser.py
Install Playwright in your local Python environment before using
connect_playwright(): pip install playwright.Watch or take over
Visible browser mode gives you a live web viewer:live_view.py
viewer_url when you want to watch the agent work, debug a failing flow, or take over for a sensitive step such as login. Give display_url to tools that expect a VNC display.
This is especially useful for computer-use agents. The model can use screenshots and UI actions, while you keep a human-readable view into what is happening.
Keep browser state between runs
Useprofile_id when a workflow needs cookies, local storage, or login state again later. Each profile gets its own sandbox browser state.
browser_profile.py
Collect screenshots and artifacts
Browser sandboxes can save screenshots and collect session files before the sandbox stops.browser_artifacts.py
collect_artifacts() before leaving the with block when you want logs, downloads, and recordings from that run.
Keep agents safe
Browser sandboxes are designed for untrusted web pages and agent-generated actions, but you still decide what the agent is allowed to do.- Use a fresh sandbox for untrusted tasks.
- Use separate
profile_idvalues for separate sites, accounts, or customers. - Pass only the environment variables the browser task needs.
- Watch the live viewer before approving high-impact actions.
- Treat page text, screenshots, downloads, and prompts from websites as untrusted input.
Related
- Browser and desktop sandboxes for the full Python API
- Browser and desktop options for viewport, profile, recording, and resource options
- AI agent integration for framework examples
