[Go to site: main page, start]

Skip to main content
agent.py runs the agent loop and its Python REPL on your machine. Model requests go to the Browser Use gateway (bu-4.0), and the REPL drives a Browser Use Cloud browser over CDP. One Browser Use key (BROWSER_USE_API_KEY) runs both. agent.py runs the agent loop and its Python REPL on your machine. Model requests go to the Browser Use gateway (bu-4.0), and the REPL drives a Browser Use Cloud browser over CDP. One Browser Use key (BROWSER_USE_API_KEY) runs both.

1. Install

Python 3.11 or newer.
Pin the exact version with ==, never >=: browser-use moves fast, and a new release can break your code. Upgrade on purpose by changing the pin.

2. Set your API key

Create a key in Browser Use Cloud and export it:
The key runs the default model, cloud browsers, web search, the CLI and the MCP server. A .env file in the working directory is read on import, so BROWSER_USE_API_KEY=bu_... there works too. Prefer to sign in from the terminal? Run browser-use login (with uv: uv run browser-use login). It opens your browser and stores the key in ~/.config/browser-harness/auth.json (over SSH, add --device-code). When BROWSER_USE_API_KEY is set, it wins over the stored key. Without a key, an interactive desktop run opens Browser Use login and continues after approval. Login creates and saves the key automatically. Set BROWSER_USE_AUTO_LOGIN=false to disable this. Servers, CI, notebooks and piped input keep the missing-key error and terminal login instructions.

3. Run an agent

Save this as agent.py:
This runs bu-4.0 (BU 4.0) on the Browser Use gateway and drives a Browser Use Cloud browser, which stops when the run ends. The browser prints its live view URL to stderr; Browser(live_view=True) also opens it, and Browser(live_view=False) hides it. Anyone with that URL can control the browser. In async code, use await agent.run(). In a script, start it with asyncio.run(...); in Jupyter, await agent.run() directly in a cell.

Local browser, your own model

Browser('chromium') uses the Chrome, Chromium or Edge you have installed. With none installed, run browser-use install once to download Chromium. See Browsers and Models.

What it costs

The library is free. The Browser Use model and cloud browsers bill to your Browser Use account; see pricing. Runs report model and judge costs, plus any web searches, in result.cost_usd when model pricing is known; otherwise it is None. Cloud browser and proxy charges are separate.

Next

Examples

Runnable scripts: forms, extraction, logins, parallel agents, files.

All parameters

Every Agent and Browser option with its default.

Agent

Options, budgets and how to write tasks.

Output

Typed results with output_model_schema.

Secrets

Pass login secrets by name and scope where they can be typed.

Migrating from 0.x

What changed in 1.0.