- Run the finished example: clone and run with two commands
- Research across multiple pages: reuse one Browserbase session to scan multiple pages
- AI actions with Stagehand: natural-language browser actions for agentic flows
What you need
- A Runloop API key
- A Browserbase API key and project ID
- Python 3.12+ and
pip, or Node.js 18+ andnpm
Environment variables
Instead of exporting the Browserbase keys, store them as Runloop account secrets and map them into the devbox at runtime. See Account Secrets.
Run the finished example
Clone the repo, install dependencies, then create the blueprint and run the browser task.create-blueprint bakes the Browserbase SDK and the Playwright client into a reusable blueprint, and run creates a devbox from it, uploads the agent, and drives a Browserbase browser. The rest of this guide walks through each of those pieces.
How the example is built
To build it yourself, install the Runloop SDK locally. The devbox installs the Browserbase SDK and Playwright client itself (baked into the blueprint below), so nothing else is needed on your machine.Create a blueprint with the Browserbase SDK
Bake the Browserbase SDK and the Playwright client into a blueprint once so every devbox starts ready, with no install step. There is noplaywright install chromium: the browser runs on Browserbase, so the devbox needs only the Playwright client library.
Create a devbox and run a browser task
Create a devbox from the blueprint with the Browserbase keys injected, then have it create a Browserbase browser and drive it with Playwright over CDP. The agent connects tosession.connect_url and runs ordinary Playwright code against the remote browser.
Here the agent returns structured JSON (title, headings, and link count) rather than a single string, which is the first useful browser primitive. The TypeScript version below orchestrates Runloop from Node, but the in-devbox agent is still Python, so the blueprint only needs the Python Browserbase SDK.
The Browserbase SDK and the Playwright client are the only dependencies the devbox needs. There is no Chromium install, because the browser runs on Browserbase and
connect_over_cdp drives it remotely.Research across multiple pages
To research several pages, reuse one Browserbase session: it avoids creating a session per page and preserves cookies and history. Connect Playwright once, define a reusablescan function that navigates and returns clean JSON, then call it for each URL. This code goes in the same in-devbox agent shown above.
The TypeScript snippets connect with
playwright-core, which has no bundled browser. That is the point: the browser runs on Browserbase, so the client needs only the Playwright protocol, not a local Chromium.AI actions with Stagehand
When an agent should not hard-code selectors, use Stagehand, Browserbase’s AI browser-automation framework. You describe an action in natural language and a model resolves it against the live page at runtime. The primitives areact (do something), extract (pull typed data), and observe (see what’s actionable). Stagehand runs on Browserbase and needs a model API key in addition to your Browserbase keys.
Stagehand runs the browser automation on Browserbase, so the model issues fewer round-trips than thousands of individual CDP calls. It is the lower-chatter path for high-volume, multi-step flows.
How the integration works internally
- A devbox boots from a blueprint with the Browserbase SDK and Playwright client already installed.
BROWSERBASE_API_KEYandBROWSERBASE_PROJECT_IDare injected into the devbox environment.- The agent calls
sessions.create()to get a Browserbase cloud browser session. - It connects Playwright to the session with
chromium.connect_over_cdp(session.connect_url)and drives the remote browser. No local Chromium. - Results return to the devbox; the orchestrator reads them and shuts the devbox down. The session is released with
sessions.update(..., status="REQUEST_RELEASE").
Common issues
resource_size_requestrejected- The enum is upper-case (
SMALL,MEDIUM,LARGE, …). Lower-case values return a 400.
- The enum is upper-case (
- Browserbase auth errors inside the devbox
- Confirm both
BROWSERBASE_API_KEYandBROWSERBASE_PROJECT_IDwere passed viaenvironment_variableswhen creating the devbox.
- Confirm both
connect_over_cdpcannot connect- Use
session.connect_urlfrom a freshly created session. A session that has timed out or been released will refuse the connection.
- Use
- Advanced stealth or proxies rejected
- Proxies need the Developer plan; advanced stealth and verified mode need a top-tier plan. The API returns a 403 on lower plans; degrade to a plain session.
Next Steps
- Full runnable source: the Browserbase example
- Review Devbox overview and Blueprints
- Read Browserbase’s Playwright quickstart and Stagehand docs
