ARCHITECTURE · COMPUTER USE · 5 MIN READ
A browser or coding agent in a sandbox
Put the working environment behind an explicit execution boundary.
Jump to a section 11 sections
EXAMPLE USE CASE
Read a local order page and prepare a draft preview
A browser task needs to inspect a status and prepare reviewable text while avoiding external network effects.
- Input
- A local fixture page with A104 = packed and a Prepare draft button.
- Expected output
- A visible draft preview saying Order A104 is packed.
- Success check: The test asserts the status, clicks the button, and verifies the resulting draft; all network requests are blocked.
- Try a failure: Change the displayed status or remove the button. The workflow must fail its locator/assertion instead of claiming success.
Example scope: A real Playwright browser test on a local fixture. Browser contexts isolate browser state; OS/container isolation and a model planner are separate requirements.
Identify the intended destination, resources and actions before opening a browser session.
Choose a bounded allowed action from current page state and verify the result before continuing.
allowed actionTo 03 · Isolated browserproposed writeTo 06 · Approval gateSeparate sessions, credentials, filesystem access and runtime resources. A browser context alone is not an OS sandbox.
requestTo 04 · Network boundaryEnforce egress and navigation rules outside page text; restrict downloads and internal network access.
page resultTo 05 · Observed pageInspect authoritative DOM/page state and keep redacted evidence. Treat page instructions as untrusted content.
Bind review to the actual proposed submission, recipient and payload before a consequential external write.
approved actionBack to 03 · Isolated browser
Choose a bounded allowed action from current page state and verify the result before continuing.
Components for this use case
- Playwright owns deterministic browser actions. Docker, E2B or another runtime can supply process/filesystem limits. The application supplies network and action policy.
- A model can choose a next browser action, but the executor must keep its allowlist, time budget and approval rules outside model control.
Create the boundary
- Give each task an isolated workspace or browser context with a defined lifetime.
- Decide which domains, files, commands, and credentials are accessible.
- A dedicated sandbox runtime supplies enforcement beyond the prompt.
Observe before acting again
- Capture the result of each command or browser action.
- Check the actual page state or file contents before continuing.
- Treat a timeout as an uncertain result rather than proof that nothing happened.
Review and clean up
- Validate generated artifacts with appropriate tests or a human review.
- Download the required outputs before ending the runtime.
- Revoke task credentials and account for any external resources created during execution.
Set up the lab
- Python 3.11+ and a supported Chromium runtime.
- This local browser-context lab performs no external navigation; a context alone is not an operating-system sandbox.
python3 -m venv .venv
source .venv/bin/activate
pip install playwright
playwright install chromiumImplement the example
Save as browser_lab.py
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
context = browser.new_context(accept_downloads=False, service_workers="block")
context.route("**/*", lambda route: route.abort())
page = context.new_page()
page.set_content('''<main><h1>Order A104</h1><p id="status">packed</p>
<button id="draft" onclick="document.querySelector('#preview').hidden=false">
Prepare draft</button><p id="preview" hidden>Order A104 is packed.</p></main>''')
assert page.locator("#status").inner_text() == "packed"
assert not page.locator("#preview").is_visible()
page.get_by_role("button", name="Prepare draft").click()
assert page.locator("#preview").is_visible()
assert page.locator("#preview").inner_text() == "Order A104 is packed."
print({"status":"packed", "draft":page.locator("#preview").inner_text(), "sent":False})
context.close()
browser.close()Run and verify
python browser_lab.py- The browser reads packed, prepares a visible draft and verifies its exact content.
- The action has an observable local effect; no external message is sent and network requests are blocked.
Troubleshooting and failure tests
- A screenshot alone does not establish that a transaction completed. Inspect authoritative page state.
- Browser-generated security warnings, login challenges and user handoffs need explicit application states.
Before production
- Run in a disposable container or VM, restrict filesystem mounts and network access, and isolate each user session.
- Capture redacted artifacts, enforce action budgets and require approval before consequential external writes.