Running Browser Use in Production, Plus a Capstone Agent

7 min read

A browser agent on a laptop is a demo. A browser agent in production is a service: it runs headless, many at a time, on untrusted pages, with secrets nearby, and it must return something useful even when it fails. This last part covers the production checklist for browser-use 1.0.9, then builds a small capstone agent that uses every guard rail from the series.

Hand-drawn diagram: inside a sandbox boundary such as a container or gVisor, your service with a queue and API sends a task to the agent process running browser-use 1.0; the agent drives headless Chromium at 1440 by 900 over CDP and writes checkpoints and files to a workspace directory; allowed_domains and egress rules sit under the browser; outside, a remote browser such as Browser Use Cloud or Browserbase can be reached by CDP over wss instead

Problem: where does the browser run?

You have three choices, each listed in the README and migration guide:

OptionHowGood forWatch out for
Local headless ChromiumBrowser('chromium', headless=True)Full control, no per-hour feeYou run and patch Chrome; no proxy support yet for local Chromium
Browser Use CloudBrowser() (the default)No browser ops; cloud proxy country, cloud profilesPer-hour browser cost; data leaves your network
Any remote CDP browserBrowser(cdp_url='wss://...')Other hosted browsers such as Browserbase, or your own fleetYou trust that provider with the session

The cloud quickstart describes two API paths on API V4. You can send a whole task to POST /api/v4/runs and let Browser Use's agent drive. Or you create a browser with POST /api/v4/browsers and connect your own Playwright or browser-use code to its cdpUrl. A test browser started from the quickstart stops itself after 5 minutes.

The README lists cloud browsers at $0.06 per browser-hour. We did not run cloud or Browserbase sessions for this series; the runs here all use local headless Chromium.

Problem: headless is a different browser

Headless Chrome is still Chrome, but it has no screen. The migration guide says local headless runs at 1440 x 900. Our page_info() calls reported a 1440 x 757 viewport, the window minus browser chrome. Pages that adapt to screen size will lay out for that size, and screenshots will match it. If your task depends on a mobile layout, set it explicitly rather than assuming.

Problem: the agent runs model-written code

This is the big one. In 1.0, the model writes Python and it runs as your user. The migration guide's trust model lists what that code can reach: files your user can read, other processes' environment on Linux, and any local browser's unauthenticated debugging port. Its repeated advice is to run untrusted tasks in a container or VM.

Practical layers, from outside in:

  1. A sandbox. A container at minimum. For stronger isolation, a user-space kernel like gVisor intercepts system calls so a compromised process cannot talk to the host kernel directly. The Deep Agents series has a full part on this: How to Stop a Deep Agent's Shell From Harming Your Host.
  2. No secrets in the environment. The REPL already drops variables whose names contain KEY, TOKEN, SECRET, PASSW, CREDENTIAL or AUTH. But the guide warns the worker can read the parent's environment through /proc. So keep provider keys out of the container if you can, or behind a proxy that injects them.
  3. Egress rules. Limit outbound network at the container level. allowed_domains is a guard, not a firewall.
  4. A fresh profile per job, unless the job needs a login (Part 7).
  5. One browser per agent. The guide says parallel agents each get their own Browser.

The 1.0.0 release notes list official Docker images: browseruse/browseruse:1.0.0 and ghcr.io/browser-use/browser-use:1.0.0. The machine used for this series has no Docker, so we did not run them.

Solution: the domain guard, tested

allowed_domains works in layers, per the migration guide. The REPL helpers refuse a blocked URL before navigating. The browser blocks every main-frame navigation to a blocked host, whoever starts it, using browser-use's own CDP connection with Fetch.enable. And after every cell, any tab still on a blocked page is reset to about:blank.

We tested two of those layers against real pages:

python
import asyncio
from scripted import run
from browser_use import Browser
CELLS = [
"""new_tab('https://en.wikipedia.org/wiki/Web_scraping'); wait_for_load(); print(page_info()['url'])""",
"""try:
    goto_url('https://example.com/')
except Exception as e:
    print('blocked:', type(e).__name__, str(e)[:200])
print('now on:', page_info()['url'])""",
"""js("location.href='https://example.com/'")
import time; time.sleep(2)
print('after a JS redirect attempt:', page_info()['url'])""",
"""goto_url('https://en.wikipedia.org/wiki/Web_scraping'); wait_for_load()
heads = js("return [...document.querySelectorAll('h2')].map(h => h.textContent.trim()).slice(0,6)")
checkpoint('headings.json', heads, partial=True)
heads""",
]
async def main():
    agent, r = await run('guard', CELLS, finish_expr='json.dumps(heads)', browser=Browser('chromium', allowed_domains=['en.wikipedia.org']))
    print('PARTIAL', r.partial)
asyncio.run(main())

Terminal log of the real run: goto_url to example.com raised PermissionError, blocked: example.com is not in allowed_domains (en.wikipedia.org), and the tab stayed on the Web scraping article. A JavaScript location change to example.com was blocked too; the next output started with blocked, the browser did not load https://example.com/, and the tab was on about:blank

The rest of the real output:

text
--- output of step 4 ---
['Contents', 'History', 'Techniques', 'Legal issues', 'Methods to prevent web scraping', 'See also']

STATUS completed STEPS 5 SUCCESS True WALL 46.8s
RESULT ["Contents", "History", "Techniques", "Legal issues", "Methods to prevent web scraping", "See also"]
PARTIAL ['Contents', 'History', 'Techniques', 'Legal issues', 'Methods to prevent web scraping', 'See also']

Both paths were stopped. The helper raised a PermissionError the model can read. The JavaScript navigation never loaded example.com, and the tab was reset to about:blank. Then checkpoint(..., partial=True) saved the headings so they would survive even if the run had died; here they also show up as result.partial.

The guide is just as clear on what the guard does not stop: fetch() and other subresources from an allowed page, the REPL's own Python networking (only http_get is checked), iframes of other sites inside an allowed page, and model code that goes around browser-use on purpose. That is why the sandbox comes first.

flowchart TD
  N[Navigation request] --> H{From a helper?}
  H -->|goto_url, new_tab, http_get| R1[Layer 1: refuse with PermissionError]
  H -->|link, redirect, JS location| R2[Layer 2: Fetch interception fails it, tab to about:blank]
  R1 --> C[After each cell]
  R2 --> C
  C --> R3[Layer 3: any tab on a blocked host reset]
  X[fetch, XHR, raw sockets, iframes] -.not covered.-> S[Container and egress rules]

Problem: production needs typed results and observability

A string result is fine for a demo. A service needs a typed object, a reason when it fails and traces.

  • Typed output. Agent(output_model_schema=YourModel) makes the run return a validated Pydantic object as result.structured_output.
  • Partial results. checkpoint(..., partial=True) plus result.partial.
  • Traces. 1.0 runs on Pydantic AI, which emits OpenTelemetry spans for every model request and tool call once instrumented. The guide notes spans carry prompts and cell output unless you pass InstrumentationSettings(include_content=False).
  • Telemetry. The README documents anonymized usage telemetry and the opt-out ANONYMIZED_TELEMETRY=false. Every run in this series used that opt-out.

Capstone: a guarded section mapper

The capstone pulls it together. It maps the sections of a Wikipedia article into a typed object, with a domain guard, headless mode, a checkpoint and a typed result. The model is scripted, as everywhere in this series except the real-model runs in Part 4. The browser, the guard, the REPL and the Pydantic validation are all real.

python
import asyncio, json
from pydantic import BaseModel
from scripted import run
from browser_use import Browser

class Section(BaseModel):
    title: str
    url: str

class DocsMap(BaseModel):
    page_title: str
    sections: list[Section]

CELLS = [
"""new_tab('https://en.wikipedia.org/wiki/Chromium_(web_browser)'); wait_for_load()
rows = js(\"\"\"return [...document.querySelectorAll('#mw-content-text h2')].map(h => ({title: h.textContent.trim(), url: location.href.split('#')[0] + '#' + (h.id || h.parentElement.id)}))\"\"\")
checkpoint('sections.json', rows, partial=True)
print(len(rows), 'sections'); rows[:3]""",
"""result = {'page_title': js("return document.querySelector('h1').textContent"), 'sections': rows}
result['page_title'], len(result['sections'])""",
]
async def main():
    agent, r = await run('Map the sections of the Chromium article', CELLS, finish_expr='result',
                         browser=Browser('chromium', headless=True, allowed_domains=['en.wikipedia.org']),
                         output_model_schema=DocsMap)
    so = r.structured_output
    print('TYPE', type(so).__name__)
    print(so.model_dump_json(indent=1)[:900])
asyncio.run(main())

Real output (trimmed at 900 characters by the script):

text
--- output of step 1 ---
10 sections
[{'title': 'Licensing', 'url': 'https://en.wikipedia.org/wiki/Chromium_(web_browser)#Licensing'},
 {'title': 'Differences from Google Chrome',
  'url': 'https://en.wikipedia.org/wiki/Chromium_(web_browser)#Differences_from_Google_Chrome'},
 {'title': 'Development', 'url': 'https://en.wikipedia.org/wiki/Chromium_(web_browser)#Development'}]

--- output of step 2 ---
('Chromium (web browser)', 10)

STATUS completed STEPS 3 SUCCESS True WALL 33.4s
TYPE DocsMap
{
 "page_title": "Chromium (web browser)",
 "sections": [
  {
   "title": "Licensing",
   "url": "https://en.wikipedia.org/wiki/Chromium_(web_browser)#Licensing"
  },
  {
   "title": "Differences from Google Chrome",
   "url": "https://en.wikipedia.org/wiki/Chromium_(web_browser)#Differences_from_Google_Chrome"
  },

TYPE DocsMap is the point. The agent's answer came back as a validated Pydantic object, not a string to parse. Your service can store it, diff it against yesterday and alert on changes.

sequenceDiagram
  participant Q as Job queue
  participant A as Agent (headless, allowed_domains)
  participant C as Chromium
  participant W as Workspace
  Q->>A: task + output_model_schema=DocsMap
  A->>C: new_tab(article), read h2 headings
  C-->>A: 10 sections
  A->>W: checkpoint('sections.json', partial=True)
  A->>A: finish_from_repl('result')
  A-->>Q: result.structured_output (DocsMap)

A production checklist

AreaDo this
IsolationContainer or VM per job; gVisor or a VM for untrusted tasks
Secretssensitive_data by name; domain-scoped; keys out of the worker environment
NetworkEgress rules at the container; allowed_domains as a second guard
BudgetSet max_steps and timeout per job type
Resultsoutput_model_schema; checkpoint(partial=True) for long jobs
GradingDeterministic checks where possible; judge for open tasks (Part 10)
WallsCount bot_block_or_captcha_detected; stop and report, do not retry blindly
TelemetryDecide on ANONYMIZED_TELEMETRY; instrument OpenTelemetry without content if prompts are sensitive
VersionPin browser-use==1.0.9 exactly, as the README advises

Where to go next

For how a personal agent runs a real browser that the user can watch and take over, see Part 5 of the Muse series, Giving an Agent a Real Browser Without Losing Control.

The series started with a gap: a model that writes text and a website that wants clicks. browser-use 1.0 bridges it with the smallest tool it can, a Python cell on raw CDP, and puts its effort into the parts around it: secrets, domain guards, compaction, judges and checkpoints. Whatever library you use, those are the parts worth copying.

Sources