Skip to content
Closed
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
2 changes: 2 additions & 0 deletions contributors/emails/DELTA31TECH@live.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d31tcjg
# PR #84143
21 changes: 21 additions & 0 deletions tests/tools/test_browser_use_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,27 @@ def test_code_piped_on_stdin(self, tmp_path, monkeypatch):
assert 'got:print("hi")' in result["output"]
assert "session" not in result

def test_python_runtime_vars_are_stripped(self, tmp_path, monkeypatch):
"""Hermes' Python environment must not contaminate uvx/browser-use.

The Desktop launcher puts Hermes' Python 3.11 site-packages on
PYTHONPATH; browser-use currently runs under Python 3.12, so inheriting
that path can load ABI-incompatible extension modules.
"""
cli = _fake_cli(
tmp_path,
'cat > /dev/null\nprintf "pythonpath_set:[%s]\\npythonhome_set:[%s]\\n" "${PYTHONPATH+x}" "${PYTHONHOME+x}"\n',
)
monkeypatch.setattr(bu_cli, "_find_cli", lambda: [cli])
monkeypatch.setenv("PYTHONPATH", "/hermes/python3.11/site-packages")
monkeypatch.setenv("PYTHONHOME", "/hermes/python3.11")

result = json.loads(bu_cli.browser_exec("print(1)"))

assert result["success"] is True
assert "pythonpath_set:[]" in result["output"]
assert "pythonhome_set:[]" in result["output"]

def test_session_sets_bu_name(self, tmp_path, monkeypatch):
cli = _fake_cli(tmp_path, 'cat > /dev/null\necho "bu:$BU_NAME"\n')
monkeypatch.setattr(bu_cli, "_find_cli", lambda: [cli])
Expand Down
12 changes: 11 additions & 1 deletion tools/browser_use_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ def _blocked_url_in_code(code: str) -> Optional[str]:


def _base_subprocess_env() -> dict:
"""Return a credential-scrubbed, Python-runtime-neutral CLI environment.

Browser Use may run under a different Python version than Hermes (notably
uvx selecting Python 3.12 while Desktop embeds Python 3.11). Inheriting
PYTHONPATH or PYTHONHOME can make that isolated runtime import Hermes'
ABI-specific packages instead of its own dependencies.
"""
from tools.browser_tool import _build_browser_env

return _build_browser_env()
env = _build_browser_env()
env.pop("PYTHONPATH", None)
env.pop("PYTHONHOME", None)
return env


def _read_browser_cfg() -> dict:
Expand Down
Loading