Run Anchor Browser with Instant
Anchor Browser runs one blocking agent task in a browser session and saves sign-ins in a named profile. 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.
ANCHOR_BROWSER_START_BROWSER_SESSION opens a browser and returns its id and live_url. ANCHOR_BROWSER_PERFORM_WEB_TASK is synchronous: it returns status and result when the agent is done. ANCHOR_BROWSER_END_BROWSER_SESSION closes the browser.
What the example contains
| Part | What it does |
|---|---|
BrowserANCHOR_BROWSER_START_BROWSER_SESSION | Opens a browser. timeout_minutes sets the session length. Returns id and live_url. |
| Live view | live_url is available immediately. Embed it in an iframe. |
ProfileANCHOR_BROWSER_CREATE_PROFILE | Saves the running browser under a name you choose, such as one derived from the user ID. Anchor profiles are keyed by name. |
TaskANCHOR_BROWSER_PERFORM_WEB_TASK | Runs the agent on your prompt in the browser given by sessionId and waits for it to finish. max_steps caps the agent's steps. Returns status (success or failure) and result. There is no status loop. |
CleanupANCHOR_BROWSER_END_BROWSER_SESSION, ANCHOR_BROWSER_DELETE_PROFILE | Ends the browser and deletes the profile by name. |
import os
from composio import Composio
composio = Composio()
session = composio.create(
user_id=os.environ["COMPOSIO_USER_ID"], toolkits=["anchor_browser"]
)
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
browser = run("ANCHOR_BROWSER_START_BROWSER_SESSION", {"timeout_minutes": 5})
session_id = browser["id"]
print("Live view:", browser["live_url"])
profile_name = f"{os.environ['COMPOSIO_USER_ID']}-profile"
profile_created = False
try:
# First session for this user: save its browser as their profile.
run(
"ANCHOR_BROWSER_CREATE_PROFILE",
{"name": profile_name, "session_id": session_id},
)
profile_created = True
task = run(
"ANCHOR_BROWSER_PERFORM_WEB_TASK",
{
"prompt": "Open https://example.com and return the page title.",
"sessionId": session_id,
"max_steps": 3,
},
)
print(task["status"], task["result"])
finally:
try:
run("ANCHOR_BROWSER_END_BROWSER_SESSION", {"session_id": session_id})
finally:
if profile_created:
run("ANCHOR_BROWSER_DELETE_PROFILE", {"name": profile_name})ANCHOR_BROWSER_CREATE_PROFILE saves the running session as the user's profile when that session ends. On later sessions, pass browser: {"profile": {"name": profile_name, "persist": true}} to load the profile and save changes back. Keep each task short; split long jobs into several task calls on the same session.
All tools in this toolkit
Every Anchor Browser tool you can call with the Instant account. Any other ANCHOR_BROWSER_* tool is refused on Instant. Required arguments are listed; open a tool in the toolkit catalog for every argument and response field.
Browser sessions
| Tool | What it does | Required arguments |
|---|---|---|
ANCHOR_BROWSER_END_BROWSER_SESSION | End a specific browser session by ID. | session_id |
ANCHOR_BROWSER_GET_BROWSER_SESSION | Retrieve detailed information about a specific browser session. | session_id |
ANCHOR_BROWSER_GET_SESSION_PAGES | Retrieve all pages associated with a specific browser session. | session_id |
ANCHOR_BROWSER_START_BROWSER_SESSION | Start a new browser session with optional customizations. | None |
Agent tasks
| Tool | What it does | Required arguments |
|---|---|---|
ANCHOR_BROWSER_PERFORM_WEB_TASK | Perform autonomous web tasks using AI agents. | prompt |
Profiles
| Tool | What it does | Required arguments |
|---|---|---|
ANCHOR_BROWSER_CREATE_PROFILE | Creates a new browser profile from an active session. | name, session_id |
ANCHOR_BROWSER_DELETE_PROFILE | Delete a browser profile by ID. | name |
ANCHOR_BROWSER_GET_PROFILE2 | Retrieve details of a specific profile by its name. | name |
ANCHOR_BROWSER_LIST_PROFILES | Fetch all stored browser profiles. | None |
ANCHOR_BROWSER_UPDATE_PROFILE | Updates an existing browser profile with data from an active session. | name, session_id |
Files and recordings
| Tool | What it does | Required arguments |
|---|---|---|
ANCHOR_BROWSER_LIST_SESSION_DOWNLOADS | Retrieve metadata of files downloaded during a browser session. | session_id |
ANCHOR_BROWSER_LIST_SESSION_RECORDINGS | List all recordings for a specific browser session. | session_id |
ANCHOR_BROWSER_UPLOAD_FILE | Upload a file to a browser session as an agent resource. | session_id, file |
ANCHOR_BROWSER_UPLOAD_FILES_TO_SESSION | Uploads a file directly to a browser session for use with web forms and file inputs. | session_id, file |
Events between your processes
| Tool | What it does | Required arguments |
|---|---|---|
ANCHOR_BROWSER_SIGNAL_EVENT | Signal a specific event to be received by other processes or sessions. | event_name, data |
ANCHOR_BROWSER_WAIT_FOR_EVENT | Blocks execution until a specific named event is signaled or the timeout expires. | event_name |
Try it with your own task
Replace the task in the script with your own. For example:
Open https://github.com/trending and return the names of the top three repositories.Next steps
- Compare the other browser toolkits in Run browser agents with Instant.
- Read how to clean up.