Run Browser Use with Instant
Browser Use runs its own agent on your task and streams the run as events, with a live view. 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. Every script starts with a run() helper that executes one tool on the user's Instant account and raises if the call fails; the API scripts use an equivalent call helper and a trap that cleans up on exit. If a call fails, read Errors you may see.
BROWSER_USE_START_RUN starts Browser Use's agent on your task and returns a run id. Read the run's events with BROWSER_USE_LIST_RUN_EVENTS until it finishes; the live view URL arrives in a browser.ready event. BROWSER_USE_GET_RUN returns the final status and answer.
What the example contains
| Part | What it does |
|---|---|
RunBROWSER_USE_START_RUN | Starts the agent on your task. model picks the agent model, and max_cost_usd sets a limit for the run. Returns the run id. |
Event loopBROWSER_USE_LIST_RUN_EVENTS | Returns the run's events in order as items. Pass next_cursor back as after to read only new events. Stop when you see run.completed, run.failed, or run.cancelled. |
| Live view | A browser.ready or browser.attached event carries data.live_view_url. Embed it in an iframe so the user can watch. |
ResultBROWSER_USE_GET_RUN | run.status and run.result (or run.error) once the run has ended. |
StopBROWSER_USE_CANCEL_RUN | Cancels a run that is still going, for example when the user presses Stop. |
import os
import time
from composio import Composio
composio = Composio()
session = composio.create(
user_id=os.environ["COMPOSIO_USER_ID"], toolkits=["browser_use"]
)
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
started = run(
"BROWSER_USE_START_RUN",
{
"task": "Open https://example.com and return the page title.",
"model": "bu-ultrafast",
"max_cost_usd": 0.10,
},
)
run_id = started["id"]
cursor, live_url, finished = None, None, False
try:
while not finished:
arguments = {"run_id": run_id, "limit": 200}
if cursor:
arguments["after"] = cursor
page = run("BROWSER_USE_LIST_RUN_EVENTS", arguments)
for event in page.get("items", []):
if (
event["type"] in ("browser.ready", "browser.attached")
and live_url is None
):
live_url = event["data"]["live_view_url"]
print("Live view:", live_url)
if event["type"] in (
"run.completed",
"run.failed",
"run.cancelled",
):
finished = True
cursor = page.get("next_cursor") or cursor
time.sleep(3)
except KeyboardInterrupt:
run("BROWSER_USE_CANCEL_RUN", {"run_id": run_id})
raise
final = run("BROWSER_USE_GET_RUN", {"run_id": run_id})["run"]
print(final["status"], final.get("result") or final.get("error"))To run a follow-up task in the same browser, pass the session_id returned by the first run and set keep_alive (seconds) so the browser stays open between runs.
All tools in this toolkit
Every Browser Use tool. Required arguments are listed; open a tool in the toolkit catalog for every argument and response field.
Runs
| Tool | What it does | Required arguments |
|---|---|---|
BROWSER_USE_CANCEL_RUN | Idempotently cancel an in-flight browser-agent run; completed work cannot be resumed by this call. | run_id |
BROWSER_USE_GET_RUN | Get a run's full result, usage, and optionally its ordered input-file attachments. | run_id |
BROWSER_USE_GET_RUN_STATUS | Read a run's lightweight indexed status for caller-controlled polling. | run_id |
BROWSER_USE_LIST_RUNS | List browser-agent runs, optionally restricted to one conversation session, one page at a time. | None |
BROWSER_USE_LIST_RUN_EVENTS | Read one page of a run's execution events incrementally, with optional event output payloads. | run_id |
BROWSER_USE_START_RUN | Start an asynchronous hosted browser-agent task that may make irreversible changes on external sites, with an optional max_cost_usd run cost cap. | task |
Profiles
| Tool | What it does | Required arguments |
|---|---|---|
BROWSER_USE_CREATE_PROFILE | Create a persistent browser profile for reusable cookies and browser state. | None |
BROWSER_USE_DELETE_PROFILE | Permanently delete a persistent browser profile and its configuration. | profile_id |
BROWSER_USE_LIST_PROFILES | List or search persistent browser profiles one page at a time. | None |
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
- Compare the other browser toolkits in Run browser agents with Instant.
- To move from Browser Use to an alternative, follow Browser Use to Hyperbrowser or Browser Use to Browserbase.
- Read how to clean up.