Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors/emails/benjamin-liang@outlook.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
n1majne3
22 changes: 22 additions & 0 deletions tests/tools/test_browser_use_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ def test_browser_use_telemetry_defaults_off(self, monkeypatch):
env = bu_cli._base_subprocess_env()
assert env["ANONYMIZED_TELEMETRY"] == "false"

def test_subprocess_env_strips_parent_python_import_paths(self, monkeypatch):
"""#83427/#84841/#86006/#86104: the browser-use CLI runs under its
own Python — inherited PYTHONPATH/PYTHONHOME pointing at Hermes's
venv make it import wrong-ABI C-extensions (pydantic_core) and
crash. Both must be stripped; unrelated vars survive."""
import sys
from types import ModuleType

browser_tool = ModuleType("tools.browser_tool")
browser_tool._build_browser_env = lambda: {
"PYTHONPATH": "/hermes:/hermes/venv/lib/site-packages",
"PYTHONHOME": "/hermes/venv",
"KEEP_ME": "yes",
}
monkeypatch.setitem(sys.modules, "tools.browser_tool", browser_tool)

env = bu_cli._base_subprocess_env()

assert "PYTHONPATH" not in env
assert "PYTHONHOME" not in env
assert env["KEEP_ME"] == "yes"


class TestToolSurfaceSwap:
def test_legacy_browser_tools_hidden_in_cli_mode(self, monkeypatch):
Expand Down
10 changes: 10 additions & 0 deletions tools/browser_use_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def _base_subprocess_env() -> dict:
from tools.browser_tool import _build_browser_env

env = _build_browser_env()
# The browser-use CLI runs under its own Python (uv tool / uvx), which
# may differ from Hermes's venv Python. PYTHONPATH/PYTHONHOME inherited
# from the agent process point at Hermes's venv site-packages, and a
# child interpreter honors them ahead of its own site-packages — so the
# CLI imports compiled C-extensions (e.g. pydantic_core) built for the
# wrong interpreter and crashes on ABI mismatch (#83427, #84841, #86006,
# #86104). Strip both — the CLI manages its own environment and never
# needs Hermes's import path.
env.pop("PYTHONPATH", None)
env.pop("PYTHONHOME", None)
env.setdefault("ANONYMIZED_TELEMETRY", "false")
return env

Expand Down
Loading