Best practices for web automation agents: create a template from the browser image and connect Puppeteer, Playwright, or BrowserUse over CDP to perform page visits, interactions, screenshots, and result archiving.
Browser Use Sandbox is designed for agents that need to visit web pages, click buttons, fill in forms, archive screenshots, or scrape dynamic pages. Create a template based on the browser image (
The following example uses Node.js with Puppeteer Core. The business side does not need a full browser: Chromium/Chrome already runs inside the sandbox.
The BrowserUse Python example below additionally requires:
In the BrowserUse example, the model call uses the Bailian OpenAI-compatible endpoint:
The example flow:
For agents that drive web operations in natural language, point BrowserUse at the CDP endpoint exposed by the sandbox. The business service creates and destroys the sandbox; BrowserUse only connects to the browser session inside it.
This integration fits searching, comparing, filling forms, clicking confirmations, and producing screenshot evidence. When stable artifacts matter, have the agent write key results as JSON and keep screenshots or HTML fragments for manual review and troubleshooting.
browser): port 3000 provides the browser service, reachable over CDP from Puppeteer, Playwright, or BrowserUse.
If the task only involves page visits, clicks, screenshots, file downloads, and lightweight result extraction, Browser Use Sandbox is sufficient. When browser artifacts must be handed over to Python/Node.js in the same session for data cleaning, tabular analysis, or report generation, prefer the AIO Sandbox.
Use Cases
| Scenario | Description |
|---|---|
| Web data collection | Visit dynamic pages and extract titles, body text, tables, links, or business fields |
| Back-office automation | Log in to admin consoles, fill forms, click buttons, download reports, or archive screenshots |
| Page monitoring | Open pages on a schedule to verify key elements, take screenshots, or check performance and availability |
| Lightweight E2E testing | Run end-to-end tests in an isolated browser, keeping CI workers clean |
| Browser-tool agents | Let an agent complete multi-step web tasks through frameworks such as BrowserUse |
Recommended Flow
- Create a template based on the browser image (
browser) and obtain itstemplateCode—see Template Management. - Create a sandbox from the template with a reasonable timeout.
- Get the public host of the browser service via
sandbox.getHost(3000). - Poll
/healthuntil the browser service is ready. - Connect Puppeteer, Playwright, or BrowserUse via
wss://<sandbox-host>/ws/automation. - Perform page visits, clicks, input, screenshots, PDF generation, or downloads.
- Save structured results, screenshots, HTML, PDFs, or downloaded files to a task directory inside the sandbox.
- Read the results on the business side, then destroy the sandbox.
Prepare the Local Environment
The following example uses Node.js with Puppeteer Core. The business side does not need a full browser: Chromium/Chrome already runs inside the sandbox.
e2b is pinned to 2.31.0, the version verified in these examples. Newer SDK versions return 405 when creating a sandbox.api_key is a Bailian API Key (required), and model is optional, defaulting to qwen3-vl-plus.
Puppeteer Example
The example flow:
- Create a sandbox.
- Wait until the browser service
/healthreturns 200. - Connect to the cloud browser over CDP.
- Open
https://example.com, extract page information, and save a screenshot.
BrowserUse Integration
For agents that drive web operations in natural language, point BrowserUse at the CDP endpoint exposed by the sandbox. The business service creates and destroys the sandbox; BrowserUse only connects to the browser session inside it.
Production Advice
- Restrict each browser task to an explicit URL scope and add a domain allowlist when necessary.
- Limit downloaded file types, per-file size, total output size, and task lifetime.
- Cap the agent's maximum steps with
max_stepsto keep it from repeating the same actions. - Page content may contain prompt injection. Do not let an agent execute instructions from a page without validation.
- Isolate login state, cookies, account credentials, and business tokens per task and inject them at runtime; never bake them into the template.
- Record URLs, screenshots, key DOM summaries, tool-call traces, and result file paths.
- For manual observation or debugging, use the noVNC page built into the image:
https://<sandbox-host>/static/vnc.html?path=/ws/livestream&autoconnect=true. Thepathparameter is mandatory and must start with/—a relativews/livestreamresolves to/static/ws/livestreamand fails; the root path/vnc.htmlreturns 404. WebSocket clients can connect directly towss://<sandbox-host>/ws/livestream(equivalent alias/ws/liveview). - When a task must continue with Python/Node.js data processing after browser operations, use the AIO Sandbox.
Next Steps
- Using AIO Sandbox: Browser automation and code execution in one sandbox
- Template Management: Create a template from the browser image
- Manage and Use Instances: Instance lifecycle and data-plane operations