Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

docs: finish Anthropic launch readiness

Gregor Žuničee82bface60c
diff --git a/browser_use/integrations/anthropic/bash.py b/browser_use/integrations/anthropic/bash.py
index b06174ce1..2929041fb 100644
--- a/browser_use/integrations/anthropic/bash.py
+++ b/browser_use/integrations/anthropic/bash.py
@@ -28,6 +28,14 @@ async def _drain_bounded(stream: asyncio.StreamReader, limit: int) -> tuple[byte
return b''.join(chunks), truncated
+def _prepare_output_dir(output_dir: str | Path) -> tuple[Path, Path]:
+ root = Path(output_dir).expanduser().resolve()
+ tmp = root / '.tmp'
+ root.mkdir(parents=True, exist_ok=True)
+ tmp.mkdir(exist_ok=True)
+ return root, tmp
+
+
async def run_bash(
command: str,
*,
@@ -43,10 +51,7 @@ async def run_bash(
if max_output_bytes <= 0:
raise ValueError('max_output_bytes must be positive')
- root = Path(output_dir).expanduser().resolve()
- tmp = root / '.tmp'
- root.mkdir(parents=True, exist_ok=True)
- tmp.mkdir(exist_ok=True)
+ root, tmp = await asyncio.to_thread(_prepare_output_dir, output_dir)
process = await asyncio.create_subprocess_exec(
'/bin/bash',
'--noprofile',
diff --git a/examples/integrations/anthropic/LAUNCH_CHECKLIST.md b/examples/integrations/anthropic/LAUNCH_CHECKLIST.md
new file mode 100644
index 000000000..d314afda6
--- /dev/null
+++ b/examples/integrations/anthropic/LAUNCH_CHECKLIST.md
@@ -0,0 +1,32 @@
+# Anthropic integration launch checklist
+
+Keep this branch private until every unchecked item is complete.
+
+## Browser Use side
+
+- [x] Implement the 31 members exported by the current Anthropic browser toolset.
+- [x] Keep `BrowserUse` and `Bash` as peer tools in the runner.
+- [x] Disable `file_upload` by default.
+- [x] Resize screenshots to the API image limit.
+- [x] Bound Bash runtime and output and remove ambient credentials.
+- [x] Document owned, borrowed, remote CDP, and Browser Use Cloud sessions.
+- [x] Run focused tests, Ruff, formatting, compilation, and a borrowed-CDP smoke.
+- [ ] Replace the existing `anthropic==0.76.0` dependency with Anthropic's
+ confirmed public browser-toolset SDK version.
+- [ ] Run `quickstart.py` through the public SDK and launch model.
+
+## Release coordination
+
+- [ ] Confirm the public Python package version and supported Python versions.
+- [ ] Confirm the public model name used in the quickstart.
+- [ ] Confirm release time, embargo, Anthropic docs URL, and quickstarts URL.
+- [ ] Replace placeholders in the launch copy with the Browser Use announcement URL.
+- [ ] Push or open a PR only after explicit publication approval.
+
+## Supported file behavior
+
+Local Bash and a local browser share a filesystem. With a remote browser, an
+upload succeeds only when the file already exists on the browser host or the
+application supplies a `document_resolver` that stages approved documents
+there. Cross-host upload/download transport is a follow-up and is not claimed
+by this launch branch.
diff --git a/examples/integrations/anthropic/README.md b/examples/integrations/anthropic/README.md
index 2a2090813..99fac98f9 100644
--- a/examples/integrations/anthropic/README.md
+++ b/examples/integrations/anthropic/README.md
@@ -23,21 +23,76 @@ from anthropic import AsyncAnthropic
from browser_use.integrations.anthropic import Bash, BrowserUse
browser = BrowserUse()
-bash = Bash(output_dir="outputs")
+bash = Bash(output_dir='outputs')
async with browser, AsyncAnthropic() as client:
- runner = client.beta.messages.tool_runner(
- model=model,
- tools=[browser, bash],
- messages=[{"role": "user", "content": task}],
- )
- result = await runner.until_done()
+ runner = client.beta.messages.tool_runner(
+ model=model,
+ tools=[browser, bash],
+ messages=[{'role': 'user', 'content': task}],
+ )
+ result = await runner.until_done()
```
`BrowserUse()` creates, starts, and stops its own `BrowserSession`. To use an
existing session, pass it as `BrowserUse(session)`; the application keeps
responsibility for starting and stopping that session.
+## Existing, remote, or Cloud browser
+
+Pass any started `BrowserSession` to the driver. This is the same shape for an
+existing local browser, a remote CDP endpoint, and Browser Use Cloud:
+
+```python
+import os
+
+from anthropic import AsyncAnthropic
+from browser_use import BrowserSession
+from browser_use.integrations.anthropic import Bash, BrowserUse
+
+session = BrowserSession(cdp_url=os.environ['BROWSER_USE_CDP_URL'])
+await session.start()
+browser = BrowserUse(session)
+bash = Bash(output_dir='outputs')
+
+try:
+ async with browser, AsyncAnthropic() as client:
+ runner = client.beta.messages.tool_runner(
+ model=model,
+ tools=[browser, bash],
+ messages=[{'role': 'user', 'content': task}],
+ )
+ result = await runner.until_done()
+finally:
+ await session.kill()
+```
+
+For Browser Use Cloud, construct the session with `BrowserSession(use_cloud=True)`
+instead. Set `BROWSER_USE_API_KEY` before starting it. Bash still runs beside
+the SDK process, so files it creates are local to that process. Remote uploads
+need a browser-host path or an application `document_resolver`.
+
+## Approval callback
+
+The Anthropic SDK calls `confirm` before configured actions run. Keep
+`javascript_exec` and `file_upload` disabled unless the application needs
+them:
+
+```python
+async def confirm(context):
+ return await app.approve(
+ action=context.member,
+ tab_id=context.tab_id,
+ tab_url=context.tab_url,
+ )
+
+
+browser = BrowserUse(
+ confirm=confirm,
+ configs={'javascript_exec': {'enabled': True}},
+)
+```
+
## Browser actions
`BrowserUse` implements all browser-toolset members:
diff --git a/tests/ci/integrations/test_anthropic_browser_use.py b/tests/ci/integrations/test_anthropic_browser_use.py
index b5257f3e8..2408ce385 100644
--- a/tests/ci/integrations/test_anthropic_browser_use.py
+++ b/tests/ci/integrations/test_anthropic_browser_use.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import ast
+import asyncio
import importlib.util
import json
import os
@@ -119,6 +120,7 @@ def test_tab_result_and_browser_state_share_a_stable_snapshot() -> None:
async def test_bash_strips_environment_and_writes_in_output_dir(tmp_path: Path, monkeypatch) -> None:
monkeypatch.setenv('ANTHROPIC_API_KEY', 'must-not-leak')
+ resolved_tmp_path = await asyncio.to_thread(tmp_path.resolve)
result = json.loads(
await run_bash(
'printf "%s\\n%s\\n" "$HOME" "${ANTHROPIC_API_KEY-unset}"; pwd; printf ok > result.txt',
@@ -126,8 +128,8 @@ async def test_bash_strips_environment_and_writes_in_output_dir(tmp_path: Path,
)
)
lines = result['output'].splitlines()
- assert lines == [str(tmp_path.resolve()), 'unset', str(tmp_path.resolve())]
- assert (tmp_path / 'result.txt').read_text() == 'ok'
+ assert lines == [str(resolved_tmp_path), 'unset', str(resolved_tmp_path)]
+ assert await asyncio.to_thread((tmp_path / 'result.txt').read_text) == 'ok'
assert result['exit_code'] == 0
assert result['timed_out'] is False