Skip to main content
1

Get your API Key

Visit the Dashboard’s Overview tab:
Then copy and set the BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID environment variables in your .env file.
2

Install and create a virtual environment with UV

UV is a modern package manager for Python.
uv venv
3

Install Browserbase and Browser Use

source .venv/bin/activate # follow the `uv venv` output
uv pip install browserbase browser-use python-dotenv
4

Create the automation script

Browser Use provides a simple Browser class that accepts a CDP URL from Browserbase. Create a main.py file:
main.py
import asyncio
import os
from dotenv import load_dotenv

from browserbase import Browserbase
from browser_use import Agent, Browser, BrowserProfile, ChatAnthropic

load_dotenv()


async def main():
    bb = Browserbase(api_key=os.environ["BROWSERBASE_API_KEY"])
    session = bb.sessions.create(project_id=os.environ["BROWSERBASE_PROJECT_ID"])

    print(f"Session ID: {session.id}")
    print(f"Debug URL: https://www.browserbase.com/sessions/{session.id}")

    browser = Browser(
        browser_profile=BrowserProfile(cdp_url=session.connect_url)
    )

    llm = ChatAnthropic(model="claude-sonnet-4-6")

    agent = Agent(
        task=(
            "Go to https://www.macrumors.com/contact.php and fill in the form. "
            "Make sure to use the selectors and submit the form"
        ),
        llm=llm,
        browser=browser,
    )

    result = await agent.run()
    print(f"Result: {result}")

    await browser.stop()


if __name__ == "__main__":
    asyncio.run(main())
5

Run your script

Run your script:
uv run main.py
You should see your Browserbase session start in Browserbase. The debug URL will be printed to console for real-time session monitoring.
Important Environment VariablesMake sure you have these environment variables in your .env file:
  • BROWSERBASE_API_KEY
  • BROWSERBASE_PROJECT_ID
  • ANTHROPIC_API_KEY (or another LLM provider key)
Notes
  • The BrowserProfile(cdp_url=...) connects to your Browserbase session via CDP
  • Browser Use handles browser lifecycle, Playwright management, and cleanup automatically
  • You can configure the LLM by passing a llm parameter to Agent (e.g. ChatAnthropic, ChatOpenAI)
  • Reach out to us at support@browserbase.com for additional support

Browserbase & Browser Use Sample Code

Configure Browserbase to add additional web-browsing capabilities to your Browser Use.