Skip to content

fix(browser): approve browser_exec code like an execute_code script - #159303

Open
c2h5oh wants to merge 7 commits into
mainfrom
fix/157913-browser-exec-approval
Open

c2h5oh wants to merge 7 commits into
mainfrom
fix/157913-browser-exec-approval

Conversation

@c2h5oh

@c2h5oh c2h5oh commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

browser_exec runs its code with Python's exec() inside the harness process on this host, whichever browser it drives: local, a CDP endpoint, or a cloud browser. Until now it never went through the approval gate, so it was an unapproved way to run host code next to execute_code.

It now gets the same one-shot whole-script approval as execute_code, under its own approval key:

  • Sessions: the same ones as execute_code. Messaging gateways, plugin-injected turns, and API turns whose client can answer an approval are asked. The interactive CLI and a local viewer's own turn are not asked for each script.
  • Container backends: a terminal backend's container doesn't exempt browser_exec, because the code never runs inside it.
  • Runs nobody can answer (cron, -q, webhooks, API turns with no approval client) still run without asking, whatever cron_mode/single_query_mode/unattended_mode say. Scheduled browser runs are a documented feature, and those modes default to deny. security.md says to remove the browser toolset where that isn't wanted.
  • What the card shows: it lists what the harness loads before the code (agent_helpers.py and the workspace .env), decoded the way Python and the harness read them. A file that can't be shown in full (a FIFO, a non-regular file, more than 256 KB, undecodable) refuses the call instead of being truncated.
  • Stranded children: a background delegate_task child of an API session whose turn has ended is refused. The client it would have been asked through is gone.
  • Ordering: the URL floor and the harness lookup run first, so a call that would fail anyway never asks.

Streaming /v1/chat/completions clients that ignore the approval.request event now wait out the approval timeout on browser_exec, as they already do for dangerous terminal commands. This is documented.

Fixes #157913

browser_exec runs the model's code as Python on this host (the harness
exec()s it) whatever browser it drives, but no approval layer saw it, so a
messaging or API turn could run subprocesses with no prompt in any approval
mode. It now goes through execute_code's one-shot whole-script gate, with its
own key and wording, before anything launches. No container fast path: the
code never runs in the terminal backend. Cron, -q and unattended platforms
are not asked, so documented scheduled browser runs keep working under the
default deny modes.

Fixes #157913
…elpers, refuse before asking

Round-1 review: the approval also covers the agent_helpers.py the harness
imports before the code (an agent could otherwise hide code there behind a
harmless-looking script); presence decides who is asked, so an api_server
turn with an approval client is asked like execute_code; a denial carries
user_summary; checks that would fail anyway (bad session name, missing
harness) run before the prompt, in one helper that keeps browser_exec under
the complexity cap.
…use a stranded API child (#157913)

- The approval now lists the workspace .env the harness loads into its
  environment, not only agent_helpers.py.
- Helpers are decoded the way Python decodes source: a coding cookie
  (utf-7) could make a shown comment line run as code.
- Workspace files are read without blocking (a FIFO hung the agent), must
  be regular files under 256 KB, and are read only when someone will be
  asked; a file that cannot be shown in full refuses the call, never a
  truncated listing.
- An async delegate_task child of an api_server session whose turn ended
  ran unasked: _presence() reads the missing notifier as nobody to ask.
  It is refused like a messaging session's stranded child.
… a client (#157913)

The stranded-child refusal also caught children of sessions nobody could
ever answer (a plain chat completion, a webhook turn whose TurnRunner
notifier nobody can answer), which ran unasked before. A lease now records
whether its dispatching turn had a notifier, and only an api_server
session's child is refused.

A directory named agent_helpers.py or .env raised (and leaked its fd)
instead of refusing; the read now fstat()s first and always closes. The
.env listing is split like the harness splits it (str.splitlines), so a
\x1c line break shows as one.
@c2h5oh

c2h5oh commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 2b9e6cb — test(browser): pin .env masking at the smart approver's inpu

ℹ️ Info

CI caches · View report · View job

27 / 27 cache hits (0 misses)
4383.30 MiB restored
0 B not restored.

per-job cache results

hits

JobStepLogsRestoredΔ vs main
OS-specific tests / Windows-only tests (arm64, 1/2)Set up native ARM64 build dependencies / Cache ARM64 OpenSSL development filesview step26.23 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 1/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step222.55 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 1/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step856.03 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 2/2)Set up native ARM64 build dependencies / Cache ARM64 OpenSSL development filesview step26.23 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 2/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step222.55 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 2/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step856.03 MiB+0 B
Docs Site / docs-site-checksSet up the locked site toolchain / Restore verified PM tools without savingview step156.11 MiB+0 B
Docs Site / docs-site-checksSet up the locked site toolchain / Restore node dependency downloadsview step71.71 MiBunknown
Repository guards / Repository guardsRun ./.github/actions/setup-pm / Restore verified PM tools without savingview step156.11 MiB+0 B
Repository guards / Repository guardsRun ./.github/actions/setup-pm / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Repository guards / Repository guardsRun ./.github/actions/setup-pm / Restore node dependency downloadsview step180.90 MiB+0 B
Python tests / Run tests (2/3)Set up locked Python and test dependencies / Restore verified PM tools without savingview step154.75 MiB+0 B
Python tests / Run tests (2/3)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (2/3)Run testsview step0.10 MiBunknown
Python tests / Run tests (3/3)Set up locked Python and test dependencies / Restore verified PM tools without savingview step154.75 MiB+0 B
Python tests / Run tests (3/3)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (3/3)Restore per-file duration cacheview step0.10 MiBunknown
Python tests / Run tests (1/3)Set up locked Python and test dependencies / Restore verified PM tools without savingview step154.75 MiB+0 B
Python tests / Run tests (1/3)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (1/3)Restore per-file duration cacheview step0.10 MiBunknown
Python lints / Python lintsRun ./.github/actions/setup-pm / Restore verified PM tools without savingview step83.12 MiB+0 B
OS-specific tests / macOS-only tests (2/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step107.16 MiB+0 B
OS-specific tests / macOS-only tests (2/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step167.62 MiB+0 B
OS-specific tests / macOS-only tests (1/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step107.16 MiB+0 B
OS-specific tests / macOS-only tests (1/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step167.62 MiB+0 B
OS-specific tests / Windows-only testsSet up locked Python and test dependencies / Restore verified PM tools without savingview step236.13 MiB+0 B
OS-specific tests / Windows-only testsSet up locked Python and test dependencies / Restore uv dependency downloads and buildsview step102.91 MiB+0 B

misses

none

Compressed archive bytes. Not-restored bytes use the main-size reference; missing sizes remain unknown.


debug info

CI timings

CI timings · View report · View job

Wall time 6m15s vs 6m23s (-2.1%). 6 job(s) slower, 7 faster,

  • Python lints / Python lints: +110.0s
  • Repository guards / Repository guards: +47.0s
  • OS-specific tests / Windows-only tests: -31.0s
  • OS-specific tests / Windows-only tests (arm64, 1/2): -27.0s
  • Python tests / Run tests (3/3): +22.0s

@alt-glitch alt-glitch added P3 Low — cosmetic, nice to have tool/browser Browser automation (CDP, Playwright) tool/code-exec execute_code sandbox type/security Security vulnerability or hardening labels Nov 23, 2026
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The change affects host-side Python runs through the browser tool.

The PR should not merge until the harness is bound to the workspace contents that were approved.

Findings

  1. P1 Security Approved helpers can change ▶
Fix with agent prompt
### Issue 1
tools/browser_use_cli.py:undefined-797
The approval is not tied to the workspace files that actually run. `_workspace_listing` reads and closes them before the approval wait, but the harness later loads the same writable paths. Concurrent calls share the task’s workspace, so a `write_file` call can create or replace `agent_helpers.py` while the browser prompt is open. Approving the earlier listing then runs unseen host Python.

Preserve the approved file contents for the harness to load, including the absence of files, rather than approving text and later reopening mutable paths.

**How this was verified:** Concurrent workers receive the same task ID, the approval retains only a listing string, and the launch passes the workspace path without binding it to the approved contents.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds whole-script approval for browser_exec before the harness starts.

  • Browser scripts now get whole-script approval before the harness runs them.
  • API browser tasks stop when their approval client is gone.

Reviews (2) · Last reviewed commit: "test(browser): pin .env masking at the s..." · Reviewed by Greptile

Comment thread tools/browser_use_cli.py Resolved
Comment thread tools/browser_use_cli.py Outdated
"dashes, or underscores (e.g. 'r7k2').")
from tools.approval import check_browser_exec_guard
try:
guard = check_browser_exec_guard(lambda: code + _workspace_listing(task_id))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Approved helpers can change

The approval is not tied to the workspace files that actually run. _workspace_listing reads and closes them before the approval wait, but the harness later loads the same writable paths. Concurrent calls share the task’s workspace, so a write_file call can create or replace agent_helpers.py while the browser prompt is open. Approving the earlier listing then runs unseen host Python.

Preserve the approved file contents for the harness to load, including the absence of files, rather than approving text and later reopening mutable paths.

How this was verified: Concurrent workers receive the same task ID, the approval retains only a listing string, and the launch passes the workspace path without binding it to the approved contents.

Knowledge Base Used: Agent tools and guardrails

Prompt To Fix With AI
This is a comment left during a code review.
Path: tools/browser_use_cli.py
Line: 797

Comment:
**Approved helpers can change**

The approval is not tied to the workspace files that actually run. `_workspace_listing` reads and closes them before the approval wait, but the harness later loads the same writable paths. Concurrent calls share the task’s workspace, so a `write_file` call can create or replace `agent_helpers.py` while the browser prompt is open. Approving the earlier listing then runs unseen host Python.

Preserve the approved file contents for the harness to load, including the absence of files, rather than approving text and later reopening mutable paths.

**How this was verified:** Concurrent workers receive the same task ID, the approval retains only a listing string, and the launch passes the workspace path without binding it to the approved contents.

**Knowledge Base Used:** [Agent tools and guardrails](https://app.greptile.com/-/switch-tenant?tenant=nous-research&next=%2Fcustom-context%2Fknowledge-base%2Fnousresearch%2Fhermes-agent%2F-%2Fdocs%2Fagent-tools-and-guardrails.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@alt-glitch alt-glitch added the comp/tools Tool registry, model_tools, toolsets label Nov 23, 2026
…e workspace changed during the wait (#157913)

The listing goes to the smart approver's model and onto a chat card, and
a workspace .env's values were never shown to either: secret values are
masked with the shared redactor (names and other values stay visible).

Another call can rewrite agent_helpers.py or .env while the prompt waits,
so the files are read again after approval and the call is refused when
they differ from what was shown.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have tool/browser Browser automation (CDP, Playwright) tool/code-exec execute_code sandbox type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: browser_exec executes arbitrary local Python without any approval gate — full bypass of the dangerous-command layer

2 participants