Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Document Rust agent terminal install
Magnus Müllerbb7fb2722a75
diff --git a/README.md b/README.mdindex ed35ab08f..9a1cc503c 100644--- a/README.md+++ b/README.md@@ -55,6 +55,11 @@ uv init && uv add browser-use && uv sync# uvx browser-use install # Run if you don't have Chromium installed```+**Experimental Rust agent:** install Browser Use Terminal for `from browser_use.rust import Agent`:+```bash+curl -fsSL https://browser-use.com/terminal/install.sh | sh+```+**2. [Optional] Get your API key from [Browser Use Cloud](https://cloud.browser-use.com/new-api-key?utm_source=github&utm_medium=readme-quickstart-api-key):**```# .envdiff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex e98aa9d2c..73bb382d4 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -274,7 +274,7 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_final_result_from_sdk_notifications_after_transport_error tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_prefers_notification_final_when_response_history_lacks_result tests/ci/test_rust_agent.py::test_rust_agent_uses_sdk_history_usage_when_events_do_not_include_usage tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_final_result_from_sdk_notifications_after_transport_error tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_recovers_projected_sdk_final_events tests/ci/test_rust_agent.py::test_rust_agent_prefers_notification_final_when_response_history_lacks_result tests/ci/test_rust_agent.py::test_rust_agent_uses_sdk_history_usage_when_events_do_not_include_usage tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`-- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_runs_through_sdk_and_reuses_session_for_followup tests/ci/test_rust_agent.py::test_rust_agent_ignores_legacy_run_process_monkeypatch_for_sdk_server -q`+- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_runs_through_sdk_and_reuses_session_for_followup -q`- terminal `cargo fmt --check`- terminal `cargo test -p browser-use-cli sdk_json_rpc_browser_create_preserves_browser_use_settings -- --nocapture`- terminal `cargo test -p browser-use-cli sdk_provider_run_config_maps_browser_use_options_to_rust_core -- --nocapture`@@ -283,7 +283,7 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- browser-use `uv run python -m py_compile browser_use/rust/service.py`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_sdk_event_dedupe_removes_projected_usage_duplicates tests/ci/test_rust_agent.py::test_rust_history_ignores_internal_browser_connection_url tests/ci/test_rust_agent.py::test_rust_agent_default_llm_matches_browser_use_default tests/ci/test_rust_agent.py::test_rust_agent_default_llm_respects_default_llm_env tests/ci/test_rust_agent.py::test_rust_agent_exposes_logging_helper_methods tests/ci/test_rust_agent.py::test_rust_agent_telemetry_filters_empty_reconstructed_urls -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_translates_browser_use_args_to_terminal tests/ci/test_rust_agent.py::test_rust_agent_sdk_params_leave_terminal_tools_unrestricted -q`-- browser-use `uv run pytest tests/ci/test_rust_agent.py -q` (192 passed, 42 skipped legacy CLI-process tests)+- browser-use `uv run pytest tests/ci/test_rust_agent.py -q`- browser-use `uv run ruff check browser_use/rust/service.py tests/ci/test_rust_agent.py tests/ci/models/test_llm_model_factory.py`- terminal `cargo test -p browser-use-browser browser_script_http_get_many_preserves_order_and_errors -- --nocapture`- terminal `cargo test -p browser-use-browser browser_script_browser_fetch_single_returns_structured_errors_by_default -- --nocapture`@@ -345,5 +345,4 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- The production Rust path no longer uses `_run_process`/`_load_events`, legacyprocess-backed SDK adapter code, or direct CLI `run-*` command construction.- Older process-monkeypatch tests remain as test-suite debt while the production- wrapper now goes through the SDK server protocol.+ The production wrapper now goes through the SDK server protocol.diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 285423cb7..1d83db545 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -85,6 +85,7 @@ AgentNewStepCallback = ()AgentDoneCallback = Callable[[AgentHistoryList], Awaitable[None]] | Callable[[AgentHistoryList], None]logger = logging.getLogger(__name__)+TERMINAL_INSTALL_COMMAND = 'curl -fsSL https://browser-use.com/terminal/install.sh | sh'try:from lmnr import Laminar # type: ignore@@ -184,9 +185,13 @@ def find_browser_use_terminal_binary() -> str:env_path = os.environ.get('BROWSER_USE_TERMINAL_BINARY')if env_path:return env_path+ but_home = Path(os.environ.get('BUT_HOME', '~/.browser-use-terminal')).expanduser()+ but_install_dir = Path(os.environ.get('BUT_INSTALL_DIR', '~/.local/bin')).expanduser()candidates = [Path.cwd() / 'target' / 'debug' / 'browser-use-terminal',Path.cwd().parent / 'terminal' / 'target' / 'debug' / 'browser-use-terminal',+ but_home / 'packages' / 'standalone' / 'current' / 'bin' / 'browser-use-terminal',+ but_install_dir / 'browser-use-terminal',]for candidate in candidates:if candidate.exists():@@ -194,7 +199,10 @@ def find_browser_use_terminal_binary() -> str:path_binary = shutil.which('browser-use-terminal')if path_binary:return path_binary- raise RustAgentError('Could not find browser-use-terminal. Set BROWSER_USE_TERMINAL_BINARY or build the terminal CLI.')+ raise RustAgentError(+ f'Could not find browser-use-terminal. Install Browser Use Terminal with `{TERMINAL_INSTALL_COMMAND}`, '+ 'or set BROWSER_USE_TERMINAL_BINARY to a built terminal CLI.'+ )class RustSdkJsonRpcError(RustAgentError):@@ -228,14 +236,22 @@ class RustSdkClient:async def start(self) -> None:if self.process is not None and self.process.returncode is None:return- self.process = await asyncio.create_subprocess_exec(- *self.command,- stdin=asyncio.subprocess.PIPE,- stdout=asyncio.subprocess.PIPE,- stderr=asyncio.subprocess.PIPE,- env=self.env,- limit=self.stream_limit,- )+ try:+ self.process = await asyncio.create_subprocess_exec(+ *self.command,+ stdin=asyncio.subprocess.PIPE,+ stdout=asyncio.subprocess.PIPE,+ stderr=asyncio.subprocess.PIPE,+ env=self.env,+ limit=self.stream_limit,+ )+ except (FileNotFoundError, PermissionError) as exc:+ command = self.command[0] if self.command else 'browser-use-terminal'+ raise RustAgentError(+ f'Could not start Rust SDK server command {command!r}. '+ f'Install Browser Use Terminal with `{TERMINAL_INSTALL_COMMAND}`, '+ 'or set BROWSER_USE_TERMINAL_BINARY to a built terminal CLI.'+ ) from excself._reader_task = asyncio.create_task(self._read_stdout())self._stderr_task = asyncio.create_task(self._read_stderr())@@ -6306,6 +6322,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):'calculate_cost': bool(self.settings.calculate_cost),'use_vision': self.settings.use_vision,'max_actions_per_step': int(self.settings.max_actions_per_step),+ 'config_overrides': {'full_llm_input_events': True},}if self._sdk_agent_id:params['agent_id'] = self._sdk_agent_iddiff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 426ea6cf2..2c0d508ec 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -2603,6 +2603,7 @@ def test_rust_agent_translates_browser_use_args_to_terminal(monkeypatch):assert "First navigate to 'https://example.com'" in agent.taskassert env['BU_CDP_URL'] == 'wss://browser.example/devtools/browser/1'assert env['LLM_BROWSER_BROWSER_MODE'] == 'remote-cdp'+ assert 'BUT_FULL_LLM_INPUT_EVENTS' not in envparams = agent._sdk_run_params(max_steps=12, task=agent.task)assert params['max_steps'] == 12@@ -2610,10 +2611,54 @@ def test_rust_agent_translates_browser_use_args_to_terminal(monkeypatch):assert params['llm'] == {'provider': 'browser-use', 'model': 'gpt-test', 'timeout': 75}assert params['browser']['cdp_url'] == 'wss://browser.example/devtools/browser/1'assert 'cdp_headers' not in params['browser']- assert 'config_overrides' not in params+ assert params['config_overrides'] == {'full_llm_input_events': True}assert "First navigate to 'https://example.com'" in params['task']+def test_rust_terminal_binary_missing_error_mentions_install(monkeypatch):+ import browser_use.rust.service as rust_service++ monkeypatch.delenv('BROWSER_USE_TERMINAL_BINARY', raising=False)+ monkeypatch.setattr(rust_service.Path, 'exists', lambda self: False)+ monkeypatch.setattr(rust_service.shutil, 'which', lambda binary: None)++ with pytest.raises(rust_service.RustAgentError) as exc_info:+ rust_service.find_browser_use_terminal_binary()++ message = str(exc_info.value)+ assert 'https://browser-use.com/terminal/install.sh' in message+ assert 'BROWSER_USE_TERMINAL_BINARY' in message+++def test_rust_terminal_binary_finds_default_terminal_install(monkeypatch, tmp_path):+ import browser_use.rust.service as rust_service++ binary = tmp_path / '.browser-use-terminal' / 'packages' / 'standalone' / 'current' / 'bin' / 'browser-use-terminal'+ binary.parent.mkdir(parents=True)+ binary.write_text('#!/bin/sh\n')++ monkeypatch.delenv('BROWSER_USE_TERMINAL_BINARY', raising=False)+ monkeypatch.chdir(tmp_path)+ monkeypatch.setenv('BUT_HOME', str(tmp_path / '.browser-use-terminal'))+ monkeypatch.setenv('BUT_INSTALL_DIR', str(tmp_path / '.local' / 'bin'))+ monkeypatch.setattr(rust_service.shutil, 'which', lambda binary_name: None)++ assert rust_service.find_browser_use_terminal_binary() == str(binary)+++async def test_rust_sdk_client_start_wraps_missing_binary_error():+ import browser_use.rust.service as rust_service++ client = rust_service.RustSdkClient(['/definitely/missing-browser-use-terminal'], env={})++ with pytest.raises(rust_service.RustAgentError) as exc_info:+ await client.start()++ message = str(exc_info.value)+ assert '/definitely/missing-browser-use-terminal' in message+ assert 'https://browser-use.com/terminal/install.sh' in message++def test_rust_agent_sdk_params_leave_terminal_tools_unrestricted(monkeypatch):from browser_use.rust import Agent@@ -2625,7 +2670,7 @@ def test_rust_agent_sdk_params_leave_terminal_tools_unrestricted(monkeypatch):params = agent._sdk_run_params(max_steps=8, task=agent.task)- assert 'config_overrides' not in params+ assert params['config_overrides'] == {'full_llm_input_events': True}assert 'tool_allowlist' not in json.dumps(params)