fix(browser): strip PYTHONPATH/PYTHONHOME from browser-use CLI subprocess env - #83471
fix(browser): strip PYTHONPATH/PYTHONHOME from browser-use CLI subprocess env#83471n1majne3 wants to merge 3 commits into
Conversation
…cess env
The browser-use CLI runs under its own Python interpreter (via uvx or a
standalone binary), which may be a different version than Hermes's venv
Python (3.11). When the desktop app sets PYTHONPATH to point at the
Hermes venv site-packages, the CLI imports compiled extensions (e.g.
pydantic_core._pydantic_core.cpython-311-*.so) built for the wrong
interpreter version, causing:
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'
hermes_subprocess_env() already strips VIRTUAL_ENV / CONDA_PREFIX via
_ACTIVE_VENV_MARKER_VARS for the same reason — PYTHONPATH is the same
class of leak and must be stripped from the browser-use subprocess env.
Closes NousResearch#83427
|
Confirmed this fix against current I also tested a focused regression test for this PR and proved that it bites:
The current PR has the correct production change. This small test would make the regression contract explicit under def test_subprocess_env_strips_parent_python_import_paths(self, monkeypatch):
"""uvx must resolve its own isolated dependencies, not Hermes's venv."""
monkeypatch.setattr(
"tools.browser_tool._build_browser_env",
lambda: {
"PYTHONPATH": "C:/hermes;C:/hermes/venv/Lib/site-packages",
"PYTHONHOME": "C:/hermes/venv",
"KEEP_ME": "yes",
},
)
env = bu_cli._base_subprocess_env()
assert "PYTHONPATH" not in env
assert "PYTHONHOME" not in env
assert env["KEEP_ME"] == "yes"This checks both isolation variables while confirming unrelated Browser Use environment values are preserved. |
|
Merged on |
Problem
browser_execcrashes on every call when the agent process hasPYTHONPATHpointing at the Hermes venv (e.g. the desktop app):The browser-use CLI runs under its own Python interpreter (via
uvxor a standalone binary) — typically 3.12/3.13. The inheritedPYTHONPATHpoints at Hermes's venv site-packages (Python 3.11), so the CLI imports compiled extensions likepydantic_core._pydantic_core.cpython-311-darwin.sofrom the wrong interpreter. The ABI mismatch causes theModuleNotFoundError.Root Cause
_base_subprocess_env()intools/browser_use_cli.pydelegates to_build_browser_env()→hermes_subprocess_env(), which copiesos.environincludingPYTHONPATH. Whilehermes_subprocess_env()already stripsVIRTUAL_ENV/CONDA_PREFIXvia_ACTIVE_VENV_MARKER_VARS,PYTHONPATHis not stripped — it is the same class of cross-version leak.Fix
Strip
PYTHONPATHandPYTHONHOMEfrom the browser-use subprocess env in_base_subprocess_env(). The CLI manages its own interpreter/venv and never needs Hermes's import path.Test Plan
PYTHONPATHset to Hermes venv site-packages, callbrowser_exec— should no longer crash.PYTHONPATH.Closes #83427