Skip to content

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

examples: enable the full Anthropic browser toolset

Gregor Žunič1799677e3763
diff --git a/examples/integrations/anthropic/README.md b/examples/integrations/anthropic/README.md
index 191a58d8e..47280e837 100644
--- a/examples/integrations/anthropic/README.md
+++ b/examples/integrations/anthropic/README.md
@@ -40,6 +40,8 @@ export ANTHROPIC_MODEL=your-model
export ANTHROPIC_LOG=info
```
+The quickstart enables all 31 browser actions plus Bash, including page JavaScript, file uploads, console logs, and network logs. JavaScript and uploads ask for approval before each call.
+
Save this as `run_browser.py`:
```python
@@ -53,6 +55,7 @@ import os
from pathlib import Path
from anthropic import AsyncAnthropic
+from anthropic.tools.browser import ConfirmContext, LocalFilePolicy
from browser_use.integrations.anthropic import Bash, BrowserUse
@@ -71,11 +74,29 @@ configured output directory; write deliverables there. Remote browser paths are
Verify outputs and report blocked work honestly."""
+async def confirm(context: ConfirmContext) -> bool:
+ if context.member not in {'file_upload', 'javascript_exec'}:
+ return True
+ details = context.input.model_dump_json(exclude_none=True)
+ answer = await asyncio.to_thread(
+ input,
+ f'Action: {context.member}\nPage: {context.tab_url}\n{details}\nAllow this action? [y/N] ',
+ )
+ return answer.strip().lower() == 'y'
+
+
async def main() -> None:
- driver = BrowserUse()
- # Remote option: get a key at https://cloud.browser-use.com/new-api-key
- # Set BROWSER_USE_API_KEY, then replace the line above with:
- # driver = BrowserUse(use_cloud=True)
+ # Set BROWSER_USE_API_KEY and add use_cloud=True below for a Cloud browser.
+ driver = BrowserUse(
+ configs={
+ 'javascript_exec': {'enabled': True},
+ 'file_upload': {'enabled': True},
+ 'read_console': {'enabled': True},
+ 'read_network': {'enabled': True},
+ },
+ confirm=confirm,
+ file_policy=LocalFilePolicy(upload_roots=[Path('uploads'), Path('outputs')]),
+ )
bash = Bash(output_dir=Path('outputs'))
async with driver, AsyncAnthropic() as client:
@@ -121,7 +142,7 @@ or opening external articles. Bash writes both files to `outputs/`.
The `SYSTEM_PROMPT` above is application guidance you can adapt. Anthropic supplies
the tool schemas and runner; this integration does not install a hidden agent prompt.
`BrowserUse` exposes structured browser actions, not a default CDP code interpreter.
-CDP is the connection used underneath. Optional `javascript_exec` evaluates JavaScript
+CDP is the connection used underneath. `javascript_exec` evaluates JavaScript
inside the page; it cannot import host libraries or execute arbitrary CDP commands.
`Bash` comes from the same Browser Use integration and runs on the SDK host.
Register both with `tools=[driver, bash]`. Browser approval callbacks do not cover Bash.
@@ -149,11 +170,7 @@ SDK host respectively.
## Browser Use Cloud
-Set `BROWSER_USE_API_KEY`, then change one line:
-
-```python
-driver = BrowserUse(use_cloud=True)
-```
+Set `BROWSER_USE_API_KEY`, then add `use_cloud=True` to the existing `BrowserUse(...)` call. Keep its `configs`, `confirm`, and `file_policy` arguments to preserve the quickstart tool selection and approvals.
Create a key at
[cloud.browser-use.com/new-api-key](https://cloud.browser-use.com/new-api-key).
@@ -225,13 +242,19 @@ when tasks may contain untrusted instructions.
## Optional actions and approvals
-Anthropic leaves `javascript_exec`, `file_upload`, `read_console`, and
-`read_network` disabled by default. Enabling JavaScript or file upload
-requires a `confirm` callback. When a callback is present, the SDK calls it
-before every browser action, so approve routine actions in code and prompt a
-person only for the actions your application treats as sensitive:
+The quickstart above enables all 31 browser actions plus Bash. A bare `BrowserUse()` follows Anthropic's defaults: 27 browser actions enabled, with `javascript_exec`, `file_upload`, `read_console`, and `read_network` off. Set `{'enabled': True}` for those four actions in `configs`, as the quickstart does, to enable the full browser toolset.
+
+Your application supplies `tools=[driver, bash]` to the runner. The SDK sends the browser toolset and its `configs` to Anthropic, and Claude chooses calls from the enabled actions. Disabled browser actions are withheld from Claude and rejected by the SDK if requested. `Bash` is a separate custom tool; registering `driver` alone does not include it.
+
+To opt out, set an action's `enabled` value to `False` in the `configs` passed to `BrowserUse(...)`. To remove Bash, use `tools=[driver]` and update the task and system prompt so they do not request shell commands.
+
+Enabling JavaScript or file upload requires a `confirm` callback. The SDK calls it before every browser action after input and policy checks. The quickstart approves routine actions automatically and prompts for JavaScript and uploads. Local uploads are restricted to `uploads/` and `outputs/`; remote uploads still need staging on the browser host.
+
+The callback flow is:
+
+<img src="./approval-gate.svg" alt="Claude requests an action. The confirmation callback either allows the driver to execute it or declines it. A callback error also prevents execution. The action output, refusal, or error returns to Claude; approval covers one action." width="100%">
-<img src="./confirmation-callback.svg" alt="A file upload passes enabled-action and file-policy checks, then reaches the application confirmation callback. Approval executes this action. A declined answer or callback error prevents execution. Browser confirmation does not cover Bash." width="100%">
+[See the detailed file-upload sequence](./confirmation-callback.svg)
```python
import asyncio
@@ -258,7 +281,7 @@ driver = BrowserUse(
'javascript_exec': {'enabled': True},
},
confirm=confirm,
- file_policy=LocalFilePolicy(upload_roots=[Path('uploads')]),
+ file_policy=LocalFilePolicy(upload_roots=[Path('uploads'), Path('outputs')]),
)
```
diff --git a/examples/integrations/anthropic/approval-gate.excalidraw b/examples/integrations/anthropic/approval-gate.excalidraw
new file mode 100644
index 000000000..eeaf7f86c
--- /dev/null
+++ b/examples/integrations/anthropic/approval-gate.excalidraw
@@ -0,0 +1 @@
+{"type":"excalidraw","version":2,"source":"https://excalidraw.com","elements":[{"id":"shape-25","type":"rectangle","x":30,"y":255,"width":120,"height":80,"angle":0,"strokeColor":"rgb(201, 107, 80)","backgroundColor":"rgba(201, 107, 80, 0.14)","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0025","roundness":null,"seed":25,"version":1,"versionNonce":25,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false},{"id":"shape-26","type":"text","x":43.3203125,"y":279,"width":93.359375,"height":31,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0026","roundness":null,"seed":26,"version":1,"versionNonce":26,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"Claude","originalText":"Claude","fontSize":28,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-27","type":"arrow","x":152,"y":295,"width":86,"height":0,"angle":0,"strokeColor":"rgb(201, 107, 80)","backgroundColor":"rgba(0, 0, 0, 1)","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0027","roundness":null,"seed":27,"version":1,"versionNonce":27,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"points":[[0,0],[86,0]],"startBinding":null,"endBinding":null,"startArrowhead":null,"endArrowhead":"arrow","elbowed":false},{"id":"shape-28","type":"text","x":158.3046875,"y":261,"width":73.390625,"height":25,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0028","roundness":null,"seed":28,"version":1,"versionNonce":28,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"request","originalText":"request","fontSize":22,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-29","type":"rectangle","x":240,"y":235,"width":210,"height":120,"angle":0,"strokeColor":"rgb(110, 147, 180)","backgroundColor":"rgba(110, 147, 180, 0.14)","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0029","roundness":null,"seed":29,"version":1,"versionNonce":29,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false},{"id":"shape-30","type":"text","x":271.296875,"y":264,"width":147.40625,"height":30,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0030","roundness":null,"seed":30,"version":1,"versionNonce":30,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"Confirmation","originalText":"Confirmation","fontSize":26,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-31","type":"text","x":298.03125,"y":296,"width":94.9326171875,"height":30,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0031","roundness":null,"seed":31,"version":1,"versionNonce":31,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"callback","originalText":"callback","fontSize":26,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-32","type":"line","x":451,"y":295,"width":37,"height":0,"angle":0,"strokeColor":"rgb(95, 91, 84)","backgroundColor":"rgba(0, 0, 0, 1)","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0032","roundness":null,"seed":32,"version":1,"versionNonce":32,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"points":[[0,0],[37,0]],"startBinding":null,"endBinding":null,"startArrowhead":null,"endArrowhead":null,"elbowed":false},{"id":"shape-33","type":"arrow","x":488,"y":295,"width":45,"height":150,"angle":0,"strokeColor":"rgb(111, 135, 103)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0033","roundness":null,"seed":33,"version":1,"versionNonce":33,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"points":[[0,0],[0,-150],[45,-150]],"startBinding":null,"endBinding":null,"startArrowhead":null,"endArrowhead":"arrow","elbowed":false},{"id":"shape-34","type":"arrow","x":488,"y":295,"width":45,"height":150,"angle":0,"strokeColor":"rgb(142, 138, 130)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0034","roundness":null,"seed":34,"version":1,"versionNonce":34,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"points":[[0,0],[0,150],[45,150]],"startBinding":null,"endBinding":null,"startArrowhead":null,"endArrowhead":"arrow","elbowed":false},{"id":"shape-35","type":"ellipse","x":484,"y":291,"width":8,"height":8,"angle":0,"strokeColor":"transparent","backgroundColor":"rgba(95, 91, 84, 1)","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0035","roundness":null,"seed":35,"version":1,"versionNonce":35,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false},{"id":"shape-36","type":"text","x":502,"y":222,"width":59.55078125,"height":25,"angle":0,"strokeColor":"rgb(94, 117, 86)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0036","roundness":null,"seed":36,"version":1,"versionNonce":36,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"Allow","originalText":"Allow","fontSize":22,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-37","type":"text","x":502,"y":346,"width":164.2783203125,"height":25,"angle":0,"strokeColor":"rgb(110, 106, 98)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0037","roundness":null,"seed":37,"version":1,"versionNonce":37,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"Decline or error","originalText":"Decline or error","fontSize":22,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-38","type":"rectangle","x":535,"y":100,"width":285,"height":90,"angle":0,"strokeColor":"rgb(143, 163, 135)","backgroundColor":"rgba(164, 182, 157, 0.32)","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0038","roundness":null,"seed":38,"version":1,"versionNonce":38,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false},{"id":"shape-39","type":"text","x":586.6875,"y":114,"width":180.625,"height":30,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0039","roundness":null,"seed":39,"version":1,"versionNonce":39,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"Driver executes","originalText":"Driver executes","fontSize":26,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-40","type":"text","x":567.65625,"y":151,"width":218.6875,"height":22,"angle":0,"strokeColor":"rgb(79, 100, 72)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0040","roundness":null,"seed":40,"version":1,"versionNonce":40,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"side effect happens here","originalText":"side effect happens here","fontSize":20,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-41","type":"rectangle","x":535,"y":400,"width":285,"height":90,"angle":0,"strokeColor":"rgb(181, 177, 168)","backgroundColor":"rgba(236, 234, 228, 1)","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0041","roundness":null,"seed":41,"version":1,"versionNonce":41,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false},{"id":"shape-42","type":"text","x":593.171875,"y":414,"width":167.65625,"height":30,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0042","roundness":null,"seed":42,"version":1,"versionNonce":42,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"No action runs","originalText":"No action runs","fontSize":26,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-43","type":"text","x":617.6953125,"y":451,"width":119.046875,"height":22,"angle":0,"strokeColor":"rgb(102, 98, 91)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0043","roundness":null,"seed":43,"version":1,"versionNonce":43,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"no side effect","originalText":"no side effect","fontSize":20,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-44","type":"arrow","x":677,"y":99,"width":587,"height":203,"angle":0,"strokeColor":"rgb(111, 135, 103)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1.8,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0044","roundness":null,"seed":44,"version":1,"versionNonce":44,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"points":[[0,0],[0,-49],[-587,-49],[-587,154]],"startBinding":null,"endBinding":null,"startArrowhead":null,"endArrowhead":"arrow","elbowed":false},{"id":"shape-45","type":"text","x":210,"y":18,"width":252.5625,"height":24,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0045","roundness":null,"seed":45,"version":1,"versionNonce":45,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"tool_result action output","originalText":"tool_result action output","fontSize":20,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-46","type":"arrow","x":677,"y":491,"width":587,"height":233,"angle":0,"strokeColor":"rgb(142, 138, 130)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1.8,"strokeStyle":"dashed","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0046","roundness":null,"seed":46,"version":1,"versionNonce":46,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"points":[[0,0],[0,79],[-587,79],[-587,-154]],"startBinding":null,"endBinding":null,"startArrowhead":null,"endArrowhead":"arrow","elbowed":false},{"id":"shape-47","type":"text","x":210,"y":538,"width":269.080078125,"height":24,"angle":0,"strokeColor":"rgb(36, 36, 36)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0047","roundness":null,"seed":47,"version":1,"versionNonce":47,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"tool_result refusal or error","originalText":"tool_result refusal or error","fontSize":20,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true},{"id":"shape-48","type":"text","x":30,"y":612,"width":361.328125,"height":22,"angle":0,"strokeColor":"rgb(102, 98, 91)","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1,"strokeStyle":"solid","roughness":0,"opacity":100,"groupIds":[],"frameId":null,"index":"a0048","roundness":null,"seed":48,"version":1,"versionNonce":48,"isDeleted":false,"boundElements":null,"updated":0,"link":null,"locked":false,"text":"Approval covers one action, not the task.","originalText":"Approval covers one action, not the task.","fontSize":20,"fontFamily":2,"textAlign":"left","verticalAlign":"top","containerId":null,"lineHeight":1.25,"autoResize":true}],"appState":{"viewBackgroundColor":"#ffffff","exportBackground":true},"files":{}}
diff --git a/examples/integrations/anthropic/approval-gate.svg b/examples/integrations/anthropic/approval-gate.svg
new file mode 100644
index 000000000..8222729a7
--- /dev/null
+++ b/examples/integrations/anthropic/approval-gate.svg
@@ -0,0 +1,69 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="850" height="660" viewBox="560 200 850 660" role="img" aria-labelledby="dgTitle dgDesc">
+ <title id="dgTitle">Confirm before the action: how confirmation gates enabled Browser Use actions</title>
+ <desc id="dgDesc">Claude sends a request to the confirmation callback. Allow runs the driver action and returns its output. Decline or callback error runs no action and returns a refusal or error. Approval covers one action, not the whole task.</desc>
+
+ <defs>
+ <style>
+ .sans { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif; }
+ .serif { font-family: Georgia, "Times New Roman", Times, serif; }
+ .mono { font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
+ .ink { fill: #242424; }
+ .muted { fill: #66625B; }
+ </style>
+ <marker id="ahReq" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto">
+ <path d="M0,1 L10,5 L0,9 Z" fill="#C96B50"/>
+ </marker>
+ <marker id="ahOk" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto">
+ <path d="M0,1 L10,5 L0,9 Z" fill="#6F8767"/>
+ </marker>
+ <marker id="ahNo" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto">
+ <path d="M0,1 L10,5 L0,9 Z" fill="#8E8A82"/>
+ </marker>
+ </defs>
+
+ <rect x="560" y="200" width="850" height="660" fill="#FAF9F5"/>
+ <!-- ============ Gated call sequence ============ -->
+
+ <!-- Claude -->
+ <rect x="590" y="455" width="120" height="80" rx="3" fill="#C96B50" fill-opacity="0.14" stroke="#C96B50" stroke-width="1.5"/>
+ <text x="650" y="504" text-anchor="middle" class="sans ink" font-size="28" font-weight="600">Claude</text>
+
+ <!-- Request -->
+ <line x1="712" y1="495" x2="798" y2="495" stroke="#C96B50" stroke-width="2" marker-end="url(#ahReq)"/>
+ <text x="755" y="481" text-anchor="middle" class="sans ink" font-size="22">request</text>
+
+ <!-- Confirmation callback -->
+ <rect x="800" y="435" width="210" height="120" rx="3" fill="#6E93B4" fill-opacity="0.14" stroke="#6E93B4" stroke-width="1.5"/>
+ <text x="905" y="488" text-anchor="middle" class="sans ink" font-size="26">Confirmation</text>
+ <text x="905" y="520" text-anchor="middle" class="sans ink" font-size="26">callback</text>
+
+ <!-- Fork -->
+ <line x1="1011" y1="495" x2="1048" y2="495" stroke="#5F5B54" stroke-width="2"/>
+ <path d="M1048 495 V345 H1093" fill="none" stroke="#6F8767" stroke-width="2" marker-end="url(#ahOk)"/>
+ <path d="M1048 495 V645 H1093" fill="none" stroke="#8E8A82" stroke-width="2" marker-end="url(#ahNo)"/>
+ <circle cx="1048" cy="495" r="4" fill="#5F5B54"/>
+
+ <text x="1062" y="442" class="sans" font-size="22" font-weight="600" fill="#5E7556">Allow</text>
+ <text x="1062" y="566" class="sans" font-size="22" font-weight="600" fill="#6E6A62">Decline or error</text>
+
+ <!-- Allowed outcome -->
+ <rect x="1095" y="300" width="285" height="90" rx="3" fill="#A4B69D" fill-opacity="0.32" stroke="#8FA387" stroke-width="1.5"/>
+ <text x="1237" y="338" text-anchor="middle" class="sans ink" font-size="26">Driver executes</text>
+ <text x="1237" y="369" text-anchor="middle" class="sans" font-size="20" fill="#4F6448">side effect happens here</text>
+
+ <!-- Denied outcome -->
+ <rect x="1095" y="600" width="285" height="90" rx="3" fill="#ECEAE4" stroke="#B5B1A8" stroke-width="1.5"/>
+ <text x="1237" y="638" text-anchor="middle" class="sans ink" font-size="26">No action runs</text>
+ <text x="1237" y="669" text-anchor="middle" class="sans muted" font-size="20">no side effect</text>
+
+ <!-- Return: allowed -->
+ <path d="M1237 299 V250 H650 V453" fill="none" stroke="#6F8767" stroke-width="1.8" marker-end="url(#ahOk)"/>
+ <text x="770" y="236" class="sans ink" font-size="20"><tspan class="mono" font-size="20">tool_result</tspan> action output</text>
+
+ <!-- Return: declined or error -->
+ <path d="M1237 691 V770 H650 V537" fill="none" stroke="#8E8A82" stroke-width="1.8" stroke-dasharray="7 5" marker-end="url(#ahNo)"/>
+ <text x="770" y="756" class="sans ink" font-size="20"><tspan class="mono" font-size="20">tool_result</tspan> refusal or error</text>
+
+ <!-- Scope note -->
+ <text x="590" y="830" class="sans muted" font-size="20">Approval covers one action, not the task.</text>
+</svg>
diff --git a/examples/integrations/anthropic/quickstart.py b/examples/integrations/anthropic/quickstart.py
index ba7aabc8e..31d9b7155 100644
--- a/examples/integrations/anthropic/quickstart.py
+++ b/examples/integrations/anthropic/quickstart.py
@@ -8,6 +8,7 @@ import os
from pathlib import Path
from anthropic import AsyncAnthropic
+from anthropic.tools.browser import ConfirmContext, LocalFilePolicy
from browser_use.integrations.anthropic import Bash, BrowserUse
@@ -26,11 +27,29 @@ configured output directory; write deliverables there. Remote browser paths are
Verify outputs and report blocked work honestly."""
+async def confirm(context: ConfirmContext) -> bool:
+ if context.member not in {'file_upload', 'javascript_exec'}:
+ return True
+ details = context.input.model_dump_json(exclude_none=True)
+ answer = await asyncio.to_thread(
+ input,
+ f'Action: {context.member}\nPage: {context.tab_url}\n{details}\nAllow this action? [y/N] ',
+ )
+ return answer.strip().lower() == 'y'
+
+
async def main() -> None:
- driver = BrowserUse()
- # Remote option: get a key at https://cloud.browser-use.com/new-api-key
- # Set BROWSER_USE_API_KEY, then replace the line above with:
- # driver = BrowserUse(use_cloud=True)
+ # Set BROWSER_USE_API_KEY and add use_cloud=True below for a Cloud browser.
+ driver = BrowserUse(
+ configs={
+ 'javascript_exec': {'enabled': True},
+ 'file_upload': {'enabled': True},
+ 'read_console': {'enabled': True},
+ 'read_network': {'enabled': True},
+ },
+ confirm=confirm,
+ file_policy=LocalFilePolicy(upload_roots=[Path('uploads'), Path('outputs')]),
+ )
bash = Bash(output_dir=Path('outputs'))
async with driver, AsyncAnthropic() as client:
diff --git a/tests/ci/integrations/test_anthropic_browser_use.py b/tests/ci/integrations/test_anthropic_browser_use.py
index 9c47b1791..15a66c0ce 100644
--- a/tests/ci/integrations/test_anthropic_browser_use.py
+++ b/tests/ci/integrations/test_anthropic_browser_use.py
@@ -254,7 +254,7 @@ def test_quickstart_uses_peer_browser_use_and_bash_tools() -> None:
source = QUICKSTART_PATH.read_text()
tree = ast.parse(source)
assert tree is not None
- assert 'driver = BrowserUse()' in source
+ assert 'driver = BrowserUse(' in source
assert "bash = Bash(output_dir=Path('outputs'))" in source
assert 'tools=[driver, bash]' in source
assert 'ActorUse' not in source