ARCHITECTURE · COMPUTER USE · 5 MIN READ

A browser or coding agent in a sandbox

Put the working environment behind an explicit execution boundary.

Download example files Code + setup + checks in a ZIP
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.

Playwright exampleDocker exampleE2B example
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
goalallowed actionrequestpage resultobserveproposed writeapproved actionUser goalAuthenticated requestAction controllerObserve, decide, verifyIsolated browserDisposable context/runtimeNetwork boundaryApproved destinationsObserved pageCurrent evidenceApproval gateExact consequential action
  1. Identify the intended destination, resources and actions before opening a browser session.

  2. Choose a bounded allowed action from current page state and verify the result before continuing.

  3. Separate sessions, credentials, filesystem access and runtime resources. A browser context alone is not an OS sandbox.

  4. Enforce egress and navigation rules outside page text; restrict downloads and internal network access.

  5. Inspect authoritative DOM/page state and keep redacted evidence. Treat page instructions as untrusted content.

  6. Bind review to the actual proposed submission, recipient and payload before a consequential external write.

Action controller

Choose a bounded allowed action from current page state and verify the result before continuing.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

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.
Shell
python3 -m venv .venv
source .venv/bin/activate
pip install playwright
playwright install chromium

Implement the example

Save as browser_lab.py

Python · 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

Shell
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.

Keep exploring

Build with the Claude Agent SDKA human approval boundary for agent actionsAn evaluation gate for agent releases