{
  "schema_version": 1,
  "diagram_type": "architecture",
  "meta": {
    "title": "Browser-Use 1.0: Python REPL, Harness Daemon & Domain Guard",
    "subtitle": "browser-use/browser-use @ 30dffbb · fixed-commit static source & CDP guard boundaries",
    "output": "docs/cases/browser-use-repl-guard.architecture.html",
    "visual_preset": "signal-flow",
    "quality_profile": "showcase",
    "repository": {
      "url": "https://github.com/browser-use/browser-use",
      "revision": "30dffbb9285e7bd8d2c81698d8a4712d5953ada5"
    }
  },
  "components": [
    {
      "id": "agent_loop",
      "type": "backend",
      "label": "Pydantic AI Agent Loop",
      "sublabel": "Tool(python, sequential=True) + finish / finish_from_repl",
      "pos": [40, 200],
      "size": [270, 92],
      "sources": [
        { "path": "browser_use/agent/loop.py", "line": 176, "label": "python() sequential cell tool" },
        { "path": "browser_use/agent/loop.py", "line": 1218, "label": "Agent tools wiring" }
      ]
    },
    {
      "id": "repl_parent",
      "type": "backend",
      "label": "Repl Parent Controller",
      "sublabel": "Spawns python -P worker; kills process tree on timeout",
      "pos": [460, 200],
      "size": [270, 92],
      "sources": [
        { "path": "browser_use/repl/session.py", "line": 304, "label": "class Repl socket parent" },
        { "path": "browser_use/repl/session.py", "line": 401, "label": "subprocess.Popen in own group" },
        { "path": "browser_use/repl/session.py", "line": 222, "label": "_kill_tree on timeout" }
      ]
    },
    {
      "id": "repl_worker",
      "type": "backend",
      "label": "REPL Worker Subprocess",
      "sublabel": "check_url() pre-check · ax.AxHelpers (bu) · Python runtime",
      "pos": [890, 200],
      "size": [270, 92],
      "tag": "not sandboxed",
      "sources": [
        { "path": "browser_use/repl/worker.py", "line": 589, "label": "check_url() helper guard" },
        { "path": "browser_use/repl/worker.py", "line": 969, "label": "ax.AxHelpers(cdp) ultrafast mode" },
        { "path": "browser_use/ax.py", "line": 39, "label": "shared EVENT_BUFFER=500" }
      ]
    },
    {
      "id": "harness_daemon",
      "type": "messagebus",
      "label": "browser-harness Daemon",
      "sublabel": "IPC relay · shared 500-event buffer per BU_NAME",
      "pos": [1320, 200],
      "size": [270, 92],
      "tag": "shared buffer",
      "sources": [
        { "path": "browser_use/repl/worker.py", "line": 527, "label": "browser_harness helpers IPC" },
        { "path": "browser_use/ax.py", "line": 5, "label": "shared buffer across daemon clients" }
      ]
    },
    {
      "id": "domain_guard",
      "type": "security",
      "label": "domains.Guard + sweep()",
      "sublabel": "Own CDP Fetch.enable (Document only) + post-cell sweep",
      "pos": [460, 410],
      "size": [280, 92],
      "tag": "main-frame only",
      "sources": [
        { "path": "browser_use/browser/browser.py", "line": 1012, "label": "Guard(ws, self.domains)" },
        { "path": "browser_use/domains.py", "line": 356, "label": "Fetch.enable (Document only)" },
        { "path": "browser_use/domains.py", "line": 423, "label": "Fetch.failRequest BlockedByClient" }
      ]
    },
    {
      "id": "chrome_cdp",
      "type": "frontend",
      "label": "Chrome Browser (CDP)",
      "sublabel": "Survives worker timeout · iframes & subresources pass",
      "pos": [1320, 410],
      "size": [270, 92],
      "sources": [
        { "path": "browser_use/browser/browser.py", "line": 1088, "label": "_sweep() resets disallowed tabs" },
        { "path": "browser_use/domains.py", "line": 18, "label": "subresources/iframes unfiltered" }
      ]
    }
  ],
  "boundaries": [
    {
      "kind": "region",
      "label": "Host Python process · Agent + REPL parent + Domain Guard",
      "wraps": ["agent_loop", "repl_parent", "domain_guard"]
    },
    {
      "kind": "security-group",
      "label": "Worker subprocess (unrestricted Python networking)",
      "wraps": ["repl_worker"]
    },
    {
      "kind": "region",
      "label": "Browser control plane · survives worker restarts",
      "wraps": ["harness_daemon", "chrome_cdp"]
    }
  ],
  "connections": [
    {
      "id": "agent-to-repl",
      "from": "agent_loop",
      "to": "repl_parent",
      "label": "repl.call('exec', code)",
      "variant": "emphasis",
      "fromSide": "right",
      "toSide": "left"
    },
    {
      "id": "repl-to-worker",
      "from": "repl_parent",
      "to": "repl_worker",
      "label": "local socket IPC",
      "variant": "emphasis",
      "fromSide": "right",
      "toSide": "left"
    },
    {
      "id": "worker-to-daemon",
      "from": "repl_worker",
      "to": "harness_daemon",
      "label": "cdp() + drain_events()",
      "variant": "emphasis",
      "fromSide": "right",
      "toSide": "left"
    },
    {
      "id": "daemon-to-chrome",
      "from": "harness_daemon",
      "to": "chrome_cdp",
      "label": "CDP commands & events",
      "variant": "emphasis",
      "fromSide": "bottom",
      "toSide": "top"
    },
    {
      "id": "guard-to-chrome",
      "from": "domain_guard",
      "to": "chrome_cdp",
      "label": "own CDP Fetch.enable + sweep()",
      "variant": "security",
      "fromSide": "right",
      "toSide": "left"
    }
  ],
  "cards": [
    {
      "dot": "amber",
      "title": "Guard is not a sandbox",
      "items": [
        "domains.py:356 filters Document requests only; fetch/images/iframes pass",
        "domains.py:19: REPL Python networking bypasses browser checks; allowed_domains ignores prohibited_domains"
      ]
    },
    {
      "dot": "cyan",
      "title": "Shared daemon event buffer",
      "items": [
        "ax.py:5-8, 39: EVENT_BUFFER=500 is shared by all clients on one BU_NAME daemon",
        "Give each ultrafast agent its own daemon or dialogs/network events can be missed"
      ]
    },
    {
      "dot": "emerald",
      "title": "Timeout isolation boundary",
      "items": [
        "session.py:222, 401: worker runs in its own process group and _kill_tree resets it",
        "Workspace files and the Chrome browser survive worker restarts"
      ]
    }
  ]
}
