Skip to main content
The fastest path is the finished Browserbase example: clone it and run two commands. The sections after it explain how the example is built so you can adapt it. New to devboxes? Start with the Quickstart.
Give a Runloop agent browser access with Browserbase: the agent runs in a devbox, the browser runs on Browserbase, and the devbox drives it by connecting Playwright over CDP to the session’s connect URL, so no Chromium ever runs in the devbox. In this guide:

What you need

  • A Runloop API key
  • A Browserbase API key and project ID
  • Python 3.12+ and pip, or Node.js 18+ and npm

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 no playwright install chromium: the browser runs on Browserbase, so the devbox needs only the Playwright client library.
From the example: python main.py create-blueprint or npm run create-blueprint. It is idempotent, so later runs reuse the built blueprint.

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 to session.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.
From the example: python main.py run or npm run run-browserbase.

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 reusable scan 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 are act (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

  1. A devbox boots from a blueprint with the Browserbase SDK and Playwright client already installed.
  2. BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID are injected into the devbox environment.
  3. The agent calls sessions.create() to get a Browserbase cloud browser session.
  4. It connects Playwright to the session with chromium.connect_over_cdp(session.connect_url) and drives the remote browser. No local Chromium.
  5. 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_request rejected
    • The enum is upper-case (SMALL, MEDIUM, LARGE, …). Lower-case values return a 400.
  • Browserbase auth errors inside the devbox
    • Confirm both BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID were passed via environment_variables when creating the devbox.
  • connect_over_cdp cannot connect
    • Use session.connect_url from a freshly created session. A session that has timed out or been released will refuse the connection.
  • 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