Run Browserbase with Instant

Browserbase runs an agent in a fresh browser for each run, keeps sign-ins in a profile, and can pause for the user to sign in. This page is part of Run browser agents with Instant. Before you start, follow Set up the project there: turn on Instant, install the SDK, and set COMPOSIO_API_KEY and COMPOSIO_USER_ID.

The script opens a browser for one user, runs a small task on https://example.com, prints the result, and then cleans up everything it created. If a call fails, read Errors you may see.

BROWSERBASE_TOOL_RUN_AGENT starts an agent run in a fresh browser. Pass the user's profile_id on every run so their sign-ins carry over. Poll BROWSERBASE_TOOL_GET_RUN until the run ends. Once it reports a sessionId, BROWSERBASE_TOOL_GET_SESSION_DEBUG_URLS returns the live_url to embed.

pauseWhen lets the agent pause for the user, for example on a sign-in page. While the run is PAUSED, show the live view, let the user sign in, then call BROWSERBASE_TOOL_RESUME_RUN once for that pause.

What the example contains

PartWhat it does
run() helperExecutes one tool on the user's Instant account and raises if it fails. Every browser example uses the same helper.
call helper and trap cleanup EXIT (API tab)call prints a tool's data, or prints the error and stops the script. cleanup runs on success and on every failure, so the browser and profile are always closed. The other API scripts use the same pattern.
Profile
BROWSERBASE_TOOL_CREATE_CONTEXT
Stores the user's cookies. Create it once per user, keep its id, and pass it as profile_id on every run.
Agent run
BROWSERBASE_TOOL_RUN_AGENT
Starts Browserbase's agent on your task in a fresh browser and returns a runId. pauseWhen tells the agent when to stop and wait for the user.
Status loop
BROWSERBASE_TOOL_GET_RUN
Reads status every few seconds. PENDING and RUNNING mean keep waiting; COMPLETED, FAILED, TIMED_OUT, and STOPPED are final.
Live view
BROWSERBASE_TOOL_GET_SESSION_DEBUG_URLS
Once the run has a sessionId, returns live_url. Embed it in an iframe so the user can watch or take control. Request it once per run; each call returns a new URL.
Resume
BROWSERBASE_TOOL_RESUME_RUN
Continues a PAUSED run after the user has done their part, such as signing in. Call it once per pause. The scripts wait for Enter in the terminal; in your application, wait for the user to confirm in your UI instead.
Resultresult.summary holds the agent's answer.
Cleanup
BROWSERBASE_TOOL_STOP_RUN, BROWSERBASE_TOOL_DELETE_CONTEXT
Stops the run if the script exits before it ends, then deletes the profile. The example deletes it at the end; in your application, delete it when the user signs out.
browserbase.py
import os
import time

from composio import Composio

composio = Composio()
session = composio.create(
    user_id=os.environ["COMPOSIO_USER_ID"], toolkits=["browserbase_tool"]
)


def run(slug: str, arguments: dict) -> dict:
    result = session.execute(
        slug, arguments=arguments, account="instant_account"
    )
    if result.result_type != "completed":
        raise RuntimeError(f"{slug} failed: {result.error}")
    return result.data


# Once per end user: a profile keeps their sign-ins between runs.
profile_id = run("BROWSERBASE_TOOL_CREATE_CONTEXT", {})["id"]
run_id = None
try:
    started = run(
        "BROWSERBASE_TOOL_RUN_AGENT",
        {
            "task": "Open https://example.com and return the page title.",
            "profile_id": profile_id,
            "pauseWhen": "A sign-in page that only the user can complete",
        },
    )
    run_id = started["runId"]
    live_url, resumed_at = None, None
    while True:
        status = run("BROWSERBASE_TOOL_GET_RUN", {"run_id": run_id})
        if status.get("sessionId") and live_url is None:
            urls = run(
                "BROWSERBASE_TOOL_GET_SESSION_DEBUG_URLS",
                {"session_id": status["sessionId"]},
            )
            live_url = urls["live_url"]
            print("Live view:", live_url)
        if status["status"] == "PAUSED":
            # Resume once per pause, and only after the user has signed in. A run
            # still paused 30 seconds after a resume has paused again: ask again.
            if resumed_at is None or time.monotonic() - resumed_at > 30:
                # Local scripts only: in your application, wait for the user to
                # confirm in your UI instead of reading from the terminal.
                input("Sign in using the live view, then press Enter: ")
                run(
                    "BROWSERBASE_TOOL_RESUME_RUN",
                    {
                        "run_id": run_id,
                        "task": "The user has signed in. Carry on.",
                    },
                )
                resumed_at = time.monotonic()
        elif status["status"] in (
            "COMPLETED",
            "FAILED",
            "TIMED_OUT",
            "STOPPED",
        ):
            run_id = None  # The run has ended: nothing to stop.
            break
        else:
            resumed_at = None
        time.sleep(3)

    print(status["status"], (status.get("result") or {}).get("summary"))
finally:
    try:
        if run_id:
            run("BROWSERBASE_TOOL_STOP_RUN", {"run_id": run_id})
    finally:
        run("BROWSERBASE_TOOL_DELETE_CONTEXT", {"profile_id": profile_id})

A simple task can be answered without opening a browser, so a run may finish with no sessionId and no live view. In an application, create the profile once per user and delete it only when the user signs out.

All tools in this toolkit

Every Browserbase tool you can call with the Instant account. Any other BROWSERBASE_TOOL_* tool needs your own Browserbase connection. Required arguments are listed; open a tool in the toolkit catalog for every argument and response field.

Agent runs

ToolWhat it doesRequired arguments
BROWSERBASE_TOOL_GET_RUNRetrieve a browser agent run's current status, result, and session details.run_id
BROWSERBASE_TOOL_GET_RUN_USAGEGet the model token usage and model cost of a browser agent run.run_id
BROWSERBASE_TOOL_LIST_RUN_MESSAGESList a page of a browser agent run's messages, oldest first, with assistant or tool roles and text or typed content parts.run_id
BROWSERBASE_TOOL_RESUME_RUNResume only a PAUSED browser agent run with optional additional input.run_id
BROWSERBASE_TOOL_RUN_AGENTStart a browser agent run to complete a task using web search and browser tools.task
BROWSERBASE_TOOL_STOP_RUNRequest that an in-progress browser agent run stop.run_id

Profiles (contexts)

ToolWhat it doesRequired arguments
BROWSERBASE_TOOL_CREATE_CONTEXTCreate a reusable browser context; the API key can select the project.None
BROWSERBASE_TOOL_DELETE_CONTEXTDelete a browser context and all its stored data (cookies, localStorage, etc.).profile_id
BROWSERBASE_TOOL_GET_CONTEXTReturn metadata for a browser context by ID.profile_id
BROWSERBASE_TOOL_LIST_PROFILESList your browser profiles (contexts), like Browser Use's List Profiles.None

Browser sessions and live view

ToolWhat it doesRequired arguments
BROWSERBASE_TOOL_CREATE_SESSIONCreate an isolated Browserbase session and return its connection details.None
BROWSERBASE_TOOL_DELETE_SESSION_DOWNLOADSDelete all file downloads from a specific browser session.session_id
BROWSERBASE_TOOL_DOWNLOAD_SESSION_ARTIFACTSDownload a completed session's generated files as a ZIP archive.session_id
BROWSERBASE_TOOL_GET_SESSIONReturn status, connection details, and timestamps for a browser session.session_id
BROWSERBASE_TOOL_GET_SESSION_DEBUG_URLSReturn live debugger and WebSocket URLs for a running browser session.session_id
BROWSERBASE_TOOL_GET_SESSION_LOGSReturn network request and response events captured during a browser session.session_id
BROWSERBASE_TOOL_GET_SESSION_REPLAYReturn HLS replay metadata and page playlist paths for a recorded session.session_id
BROWSERBASE_TOOL_GET_SESSION_REPLAY_PAGEReturn the HLS M3U8 playlist for one recorded replay page.session_id, pageId
BROWSERBASE_TOOL_LIST_SESSIONSList browser sessions, optionally filtered by status or user metadata.None
BROWSERBASE_TOOL_RELEASE_SESSIONIrreversibly request release of a running browser session, ending it before its configured timeout so Browserbase stops billing browser time.session_id
BROWSERBASE_TOOL_UPLOAD_SESSION_FILEUpload one file so browser interactions can select it in a file input field.session_id, file
BROWSERBASE_TOOL_UPLOAD_SESSION_FILESUpload multiple files to one browser session for file-input interactions.session_id, files

Files, downloads and recordings

ToolWhat it doesRequired arguments
BROWSERBASE_TOOL_DELETE_DOWNLOADDelete a download file from storage and mark it as deleted.id
BROWSERBASE_TOOL_GET_DOWNLOADGet a single download by ID as metadata or a downloadable file object.id
BROWSERBASE_TOOL_LIST_DOWNLOADSList one page of download metadata for a required browser session.session_id
BROWSERBASE_TOOL_LIST_RECORDING_DOWNLOADSPoll per-page MP4 assembly after requesting recording downloads until every page is COMPLETED or FAILED.session_id
BROWSERBASE_TOOL_REQUEST_RECORDING_DOWNLOADSStart asynchronous MP4 assembly for every recorded page of a completed session, then poll List Recording Downloads until every page is COMPLETED or FAILED.session_id

Search and page fetch

ToolWhat it doesRequired arguments
BROWSERBASE_TOOL_FETCH_PAGEFetch a page and return its content, headers, and metadata.url
BROWSERBASE_TOOL_WEB_SEARCHPerform a web search and return structured results.query

Try it with your own task

Replace the task in the script with your own. For example:

Open https://news.ycombinator.com and return the titles of the top three stories.

Next steps