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

PartWhat it does
Browser
ANCHOR_BROWSER_START_BROWSER_SESSION
Opens a browser. timeout_minutes sets the session length. Returns id and live_url.
Live viewlive_url is available immediately. Embed it in an iframe.
Profile
ANCHOR_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.
Task
ANCHOR_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.
Cleanup
ANCHOR_BROWSER_END_BROWSER_SESSION, ANCHOR_BROWSER_DELETE_PROFILE
Ends the browser and deletes the profile by name.
anchor.py
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

ToolWhat it doesRequired arguments
ANCHOR_BROWSER_END_BROWSER_SESSIONEnd a specific browser session by ID.session_id
ANCHOR_BROWSER_GET_BROWSER_SESSIONRetrieve detailed information about a specific browser session.session_id
ANCHOR_BROWSER_GET_SESSION_PAGESRetrieve all pages associated with a specific browser session.session_id
ANCHOR_BROWSER_START_BROWSER_SESSIONStart a new browser session with optional customizations.None

Agent tasks

ToolWhat it doesRequired arguments
ANCHOR_BROWSER_PERFORM_WEB_TASKPerform autonomous web tasks using AI agents.prompt

Profiles

ToolWhat it doesRequired arguments
ANCHOR_BROWSER_CREATE_PROFILECreates a new browser profile from an active session.name, session_id
ANCHOR_BROWSER_DELETE_PROFILEDelete a browser profile by ID.name
ANCHOR_BROWSER_GET_PROFILE2Retrieve details of a specific profile by its name.name
ANCHOR_BROWSER_LIST_PROFILESFetch all stored browser profiles.None
ANCHOR_BROWSER_UPDATE_PROFILEUpdates an existing browser profile with data from an active session.name, session_id

Files and recordings

ToolWhat it doesRequired arguments
ANCHOR_BROWSER_LIST_SESSION_DOWNLOADSRetrieve metadata of files downloaded during a browser session.session_id
ANCHOR_BROWSER_LIST_SESSION_RECORDINGSList all recordings for a specific browser session.session_id
ANCHOR_BROWSER_UPLOAD_FILEUpload a file to a browser session as an agent resource.session_id, file
ANCHOR_BROWSER_UPLOAD_FILES_TO_SESSIONUploads a file directly to a browser session for use with web forms and file inputs.session_id, file

Events between your processes

ToolWhat it doesRequired arguments
ANCHOR_BROWSER_SIGNAL_EVENTSignal a specific event to be received by other processes or sessions.event_name, data
ANCHOR_BROWSER_WAIT_FOR_EVENTBlocks 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