Getting Started with Anchor Browser: Your First Automation Script

Hands On
Jul 31
by Idan Raman
Your First Automation Script

Every browser automation project starts the same way: an API key, an installed SDK, and a script that either works or doesn't. This walks through that first script for Anchor Browser end to end—from installing the SDK to running a natural-language task, then stepping down to raw Playwright control over the same cloud session.

Before You Start

You need an Anchor API key, which you can generate from the API keys dashboard. Everything below assumes it's set as an environment variable, ANCHOR_API_KEY.

Install the SDK for your language:

pip install anchorbrowser
# or
npm install anchorbrowser

Your First Script: A Natural-Language Task

The fastest way to see a browser agent work is to hand it a goal in plain English and let it decide the clicks and reads itself. No selectors, no page objects:

import os
from anchorbrowser import Anchorbrowser

anchor_client = Anchorbrowser(api_key=os.getenv("ANCHOR_API_KEY"))

result = anchor_client.agent.task(
    "go to news.ycombinator.com and get the title of the first story"
)
print("Task result:", result)

Run that and Anchor spins up a cloud browser, navigates, reads the page, and hands back the answer—no local Chromium install, no headless flags to tune.

Going Lower-Level: Driving the Session Yourself

Natural-language tasks are the quickest path to a working script, but plenty of workflows still need explicit control—specific selectors, waits, and multi-step logic you don't want to leave to an agent's judgment. For that, create a session directly and connect to it over CDP with Playwright, which already speaks the same protocol:

import os
from anchorbrowser import Anchorbrowser
from playwright.sync_api import sync_playwright

anchor_client = Anchorbrowser(api_key=os.getenv("ANCHOR_API_KEY"))
session = anchor_client.sessions.create()

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(session.data.cdp_url)
    page = browser.new_page()
    page.goto("https://example.com")
    page.wait_for_load_state("networkidle")
    print(page.title())
    browser.close()

Closing the Playwright connection doesn't end the Anchor session—the cloud browser keeps running until it times out or you close it explicitly. That's what lets a multi-step script reconnect later, or lets a long extraction job keep going without a local process babysitting it.

Where to Go From Here

Both patterns point at the same underlying session, so most teams end up mixing them: an agent task for the parts of a flow that are annoying to hand-code, explicit Playwright for the parts that need to be exact every time. From here, the next steps are usually adding a proxy for the sites that care about IP reputation, and reviewing a session's live view or recording when a step behaves unexpectedly.

Anchor handles the cloud browser, the session lifecycle, and the CDP endpoint so your first script doesn't have to. Get an API key and run the example above against your own target.

Stay ahead in browser automation

We respect your inbox. Privacy policy

Welcome aboard! Thanks for signing up
Oops! Something went wrong while submitting the form.