AIO Sandbox is designed for Agent tasks where browser automation, code execution, and file processing happen in sequence. We recommend creating sandboxes from the All-In-One template: port 3000 provides the browser service, and port 5000 provides the Code Interpreter/envd service. This lets an Agent complete web access, screenshots, downloads, data cleanup, code execution, and result export in the same isolated environment.
If the task only needs to open web pages, click buttons, take screenshots, or download files, use Browser Use Sandbox. Choose AIO Sandbox only when browser artifacts need to be processed immediately by Python or Node.js.
Use Cases
| Scenario | Description |
| Analyze scraped web data | Use the browser to open dynamic pages, save HTML, screenshots, or downloaded files, then clean, aggregate, and export them with Python. |
| Automated test reports | Run browser E2E tests, then analyze logs, screenshots, and test results in the same sandbox. |
| Content production Agents | Generate web screenshots, PDFs, spreadsheets, JSON, and archives. |
| Multi-tool Agents | Combine browser automation, terminal commands, Code Interpreter, and file APIs in one session. |
Recommended Workflow
Build a business template from the All-In-One template, such as
my-all-in-one-template.Create a sandbox from the template and set a sufficient timeout. Browser cold start, page loading, and code execution all consume time.
Get the public browser service host with
sandbox.get_host(3000).Poll
/healthuntil the browser service is ready.Connect Playwright or Puppeteer through the CDP endpoint, then open pages, interact, take screenshots, and download files.
Write browser artifacts to the sandbox file system, then process them through Code Interpreter or commands.
Download result files and record the URL, action summary, screenshot paths, script version, and output results.
Kill the sandbox after the task and clean up temporary credentials and intermediate files.
Prepare the Local Environment
The following example uses Node.js to connect to the browser in an All-In-One sandbox and then execute Python code in the same sandbox. The business side only needs the SDK and Playwright Core; the browser runs in FC Agent Sandbox.
{
"name": "aio-sandbox-demo",
"version": "1.0.0",
"type": "module",
"dependencies": {
"@e2b/code-interpreter": "^2.6.1",
"playwright-core": "^1.49.0"
},
"devDependencies": {
"tsx": "^4.23.0",
"typescript": "^6.0.3"
}
}Example Code
The example flow is:
Create a
my-all-in-one-templatesandbox.Wait for the browser service
/healthendpoint to return 200.Connect to the cloud browser through CDP, open
https://example.com, and write a screenshot to the sandbox task directory.Use Code Interpreter to read the browser artifact and generate a structured summary.
import { Sandbox } from "@e2b/code-interpreter";
import { chromium } from "playwright-core";
const TEMPLATE = process.env.E2B_AIO_TEMPLATE || "my-all-in-one-template";
const BROWSER_PORT = 3000;
const TARGET_URL = "https://example.com";
const TASK_DIR = "/tmp/aio-task";
const SCREENSHOT_PATH = `${TASK_DIR}/page.png`;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
function toArrayBuffer(bytes) {
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
}
async function waitUntilHealthy(sandbox, host, token, timeoutMs = 60_000) {
const tokenHeader = token ? `-H 'X-Access-Token: ${token}' ` : "";
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
let result;
try {
result = await sandbox.commands.run(
`curl -sS -o /dev/null -w '%{http_code}' -m 4 ` +
tokenHeader +
`https://${host}/health`,
{ timeoutMs: 10_000 },
);
} catch (error) {
result = error;
}
const code = (result.stdout || "").trim();
if (code === "200") {
return;
}
await sleep(2_000);
}
throw new Error(`browser service was not ready within ${timeoutMs}ms`);
}
async function collectPage(cdpUrl, token) {
const browser = await chromium.connectOverCDP(cdpUrl, {
headers: token ? { "X-Access-Token": token } : {},
});
const contexts = browser.contexts();
const context = contexts.length ? contexts[0] : await browser.newContext();
const page = await context.newPage();
try {
await page.goto(TARGET_URL, {
waitUntil: "domcontentloaded",
timeout: 30_000,
});
const result = await page.evaluate(() => ({
url: location.href,
title: document.title,
textLength: document.body.innerText.length,
}));
const screenshot = await page.screenshot({ fullPage: true });
return { result, screenshot };
} finally {
await page.close();
await browser.close();
}
}
let sandbox;
try {
sandbox = await Sandbox.create(TEMPLATE, {
timeoutMs: 900_000,
});
const host = sandbox.getHost(BROWSER_PORT);
const token = sandbox.envdAccessToken;
const cdpUrl = `wss://${host}/ws/automation`;
await waitUntilHealthy(sandbox, host, token);
await sandbox.files.makeDir(TASK_DIR);
const { result: pageResult, screenshot } = await collectPage(cdpUrl, token);
await sandbox.files.write(SCREENSHOT_PATH, toArrayBuffer(screenshot));
const execution = await sandbox.runCode(`
import json
from pathlib import Path
page = ${JSON.stringify(JSON.stringify(pageResult))}
data = json.loads(page)
summary = {
"status": "ok",
"source": "aio-sandbox",
"title": data["title"],
"url": data["url"],
"text_length": data["textLength"],
"artifacts": [str(Path("${SCREENSHOT_PATH}"))],
}
print(json.dumps(summary, ensure_ascii=False))
`);
console.log(execution.logs.stdout);
} finally {
if (sandbox) {
await sandbox.kill();
}
}Integration Recommendations
Use a fixed task directory, such as
/tmp/aio-task/<task-id>, and keep screenshots, HTML, downloaded files, scripts, and result files in that directory.Record inputs, outputs, logs, and errors separately for the browser stage and the code stage. When troubleshooting, first determine whether the page action failed or the follow-up script failed.
Validate downloaded file type, size, and path before passing files to the code stage.
Page content and downloaded files may carry prompt injection. Do not treat web text as system instructions or high-privilege tool instructions.
Inject browser accounts, cookies, model keys, and business credentials at runtime instead of writing them into the template image.
Set the maximum page count, maximum downloaded file size, command timeout, and sandbox lifetime to prevent unbounded crawling or computation.
If you need to observe the browser in real time, connect noVNC through the All-In-One template endpoint
wss://<sandbox-host>/ws/livestream.