Skip to content

fix(browser): isolate Browser Use Python environment - #84143

Closed
d31tcjg wants to merge 2 commits into
NousResearch:mainfrom
d31tcjg:fix/browser-use-python-env-isolation
Closed

fix(browser): isolate Browser Use Python environment#84143
d31tcjg wants to merge 2 commits into
NousResearch:mainfrom
d31tcjg:fix/browser-use-python-env-isolation

Conversation

@d31tcjg

@d31tcjg d31tcjg commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Prevents the bundled Browser Use CLI from inheriting Hermes Desktop Python runtime overrides. Desktop can expose Hermes Python 3.11 site-packages through PYTHONPATH while Browser Use runs in an isolated Python 3.12 uv tool environment; the mixed ABI causes ModuleNotFoundError: pydantic_core._pydantic_core before Browser Use can start.

The fix removes PYTHONPATH and PYTHONHOME only at the Browser Use subprocess boundary, after the existing credential-scrubbed browser environment is built. Browser backend credentials, CDP routing, and workspace helper auto-import remain intact.

Related Issue

No existing issue or PR found after searching open and closed work for Browser Use, PYTHONPATH, and pydantic_core.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Update tools/browser_use_cli.py::_base_subprocess_env() to remove PYTHONPATH and PYTHONHOME before launching Browser Use.
  • Add a regression in tests/tools/test_browser_use_cli.py proving both variables are absent, not merely empty, in the child process.

How to Test

  1. From a parent process with Hermes Python 3.11 paths exported through PYTHONPATH, launch Browser Use installed as a Python 3.12 uv tool. Before this fix, startup imports Pydantic from the wrong venv and fails in pydantic_core.
  2. Run scripts/run_tests.sh tests/tools/test_browser_use_cli.py tests/tools/test_browser_use_session_expiry.py -q.
  3. Launch a fresh Hermes Desktop backend and use browser_exec to navigate to https://example.com, then evaluate document.querySelector("h1").textContent.

Verified locally:

  • 82/82 targeted Browser Use tests passed.
  • Ruff, py_compile, and git diff --check passed.
  • Browser Use doctor reported Chrome, daemon, and active browser connection healthy.
  • Live restarted Desktop browser_exec loaded Example Domain and extracted the expected DOM heading.

Checklist

Code

  • I have read the Contributing Guide.
  • My commit follows Conventional Commits.
  • I searched existing issues and PRs to make sure this is not a duplicate.
  • This PR contains only changes related to this fix.
  • All required GitHub CI checks pass, including 12 Python slices, macOS, Windows, lint/type, E2E, security, attribution, and Docker amd64/arm64.
  • I added a regression test for the bug.
  • Tested on macOS 27.0 with Hermes Python 3.11.15 and Browser Use Python 3.12.13.

Documentation & Housekeeping

  • Relevant documentation is N/A; the subprocess contract is documented in the function docstring.
  • cli-config.yaml.example changes are N/A.
  • CONTRIBUTING.md / AGENTS.md changes are N/A.
  • Cross-platform impact was considered: environment key removal uses portable dictionary operations before subprocess.run.
  • Tool description/schema changes are N/A; user-facing behavior is unchanged except that Browser Use starts successfully.

Screenshots / Logs

Live post-restart verification returned:

https://example.com/ — 🐴 Example Domain
document.querySelector("h1").textContent -> Example Domain

@alt-glitch alt-glitch added type/bug Something isn't working tool/browser Browser automation (CDP, Playwright) P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Aug 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #83471. Both patches remove PYTHONPATH and PYTHONHOME at the Browser Use subprocess boundary to prevent the same cross-Python ABI import failure; #83471 is the earlier open implementation.

@d31tcjg

d31tcjg commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed as a duplicate of #83471. Both changes strip PYTHONPATH and PYTHONHOME in _base_subprocess_env() to prevent the same cross-Python ABI import failure. Since #83471 is the earlier implementation and closes #83427, I am closing this PR in its favor. This PR’s regression test and successful CI/live Desktop validation remain available if useful. Thank you for the triage.

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

Labels

duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists tool/browser Browser automation (CDP, Playwright) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants