Skip to content

The agent that grows with you

fix(browser): strip PYTHONPATH/PYTHONHOME from browser-use CLI subprocess env

Benjamin47fd2eb7c82b
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..873934a19a8
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+n1majne3
diff --git a/tests/tools/test_browser_use_cli.py b/tests/tools/test_browser_use_cli.py
index 2de75622aea..0f6a197be9c 100644
--- a/tests/tools/test_browser_use_cli.py
+++ b/tests/tools/test_browser_use_cli.py
@@ -101,6 +101,28 @@ class TestSubprocessEnvironment:
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):
diff --git a/tools/browser_use_cli.py b/tools/browser_use_cli.py
index 7c20aaec041..15828edf354 100644
--- a/tools/browser_use_cli.py
+++ b/tools/browser_use_cli.py
@@ -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