> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anchorbrowser.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Anchor Browser is cloud browser infrastructure for AI agents and automation: browser sessions you control over CDP or REST, natural-language web tasks, versioned automation tasks, managed authentication into third-party web apps (identities with MFA), persistent volumes and profiles, recordings, live view, batch sessions, webhooks, and network options including residential proxies, extra stealth, and captcha solving for sites that block standard browsers. The for-agents page (https://docs.anchorbrowser.io/for-agents) covers authentication and the first API calls. API keys are created at https://app.anchorbrowser.io/api-keys. Append .md to any page URL for its Markdown version. The SDKs read the API key from ANCHORBROWSER_API_KEY, and REST calls send it in the anchor-api-key header. End every session you create with DELETE /v1/sessions/{id}, because a session is billed until it ends. Location targeting, captcha solving and managed authentication need the Starter plan, and extra stealth needs the Growth plan; on the Free plan, create a session with an empty body. Plans and limits are at https://docs.anchorbrowser.io/pricing. The hosted MCP server is https://api.anchorbrowser.io/v1/mcp.

# InstaBox

> Run agent code on an InstaBox machine and drive an Anchor cloud browser from it. The Anchor key stays out of the machine.

[InstaBox](https://instabox.sh) gives every agent a Linux machine of its own in the cloud, with root, Docker and coding agents already installed. This guide runs agent code on an InstaBox machine and gives it a real browser on Anchor.

Every sample is in Python and TypeScript. Tested with the InstaBox CLI 0.8.497, `instabox-sdk` 0.5.15, `@insforge/instabox-sdk` 0.11.0, the Anchor Python SDK 1.0.1 and the Anchor TypeScript SDK 1.0.0.

## What you're integrating

**Anchor SDK on an InstaBox machine → Anchor Cloud.** The machine runs your agent and its code. Chromium runs as a managed Anchor cloud session, reached over HTTPS and CDP.

* InstaBox stays the code runtime: the agent edits files, installs packages and runs commands there.
* Anchor stays the remote browser: stealth, proxies, live view and session lifecycle.
* The Anchor key is an InstaBox Org Secret. The machine holds a placeholder, and InstaBox's outbound proxy swaps in the real key on requests to `api.anchorbrowser.io`.
* A network allowlist limits the machine to Anchor's two hosts.

An InstaBox machine also has Chromium and a desktop of its own. That browser runs on the machine, from the machine's address, and needs the machine's network open to every site it visits. With Anchor the browser is outside the machine: it gets past bot detection, you watch it through Anchor's live view, and the machine itself only needs to reach Anchor.

## Before you start

Install the `instabox` CLI and sign in by following the [InstaBox quick start](https://instabox.sh/docs/quickstart). Check it works:

```bash theme={null}
instabox --version
```

```text theme={null}
instabox 0.8.497+98f164203
```

For the SDK samples, create an API key in the [InstaBox dashboard](https://dashboard.instabox.sh/api-keys) and install the SDK for your language:

```bash Python theme={null}
pip install instabox-sdk
export INSTABOX_API_KEY=ibk_...
```

```bash TypeScript theme={null}
npm install @insforge/instabox-sdk tsx
export INSTABOX_API_KEY=ibk_...
```

The TypeScript samples use top-level `await`, so set `"type": "module"` in your `package.json`.

## Save your Anchor key as an Org Secret

Create an Anchor key at [API Keys](https://app.anchorbrowser.io/api-keys). Save it as an Org Secret that may only go to Anchor's API host. With the key in `ANCHORBROWSER_API_KEY` in your shell:

```bash theme={null}
printf %s "$ANCHORBROWSER_API_KEY" \
  | instabox secrets set ANCHORBROWSER_API_KEY --host api.anchorbrowser.io
```

Without the pipe, the command asks for the value at a hidden prompt. Keep the name `ANCHORBROWSER_API_KEY`: the Anchor Python SDK reads it on its own, and the TypeScript samples pass it to the SDK.

> [!NOTE]
>
> Saving a Secret needs a signed-in owner or admin. An API key of a personal workspace is refused with `403 missing_scope` and the hint `sign in with instabox login, or use an API key of a workspace`.

## Prepare a snapshot once

Install the Anchor SDK and the Playwright client on one machine, save it as a snapshot, and start every later machine from that snapshot.

```bash theme={null}
instabox create --name anchor-prep

instabox exec anchor-prep -- "python3 -m venv ~/anchor-env && ~/anchor-env/bin/pip install -q 'anchorbrowser>=1.0' playwright"

instabox exec anchor-prep -- "mkdir -p ~/anchor && cd ~/anchor && npm init -y >/dev/null && npm install anchorbrowser playwright-core"

instabox snapshot save anchor-prep --name anchor-sandbox

instabox rm --yes anchor-prep
```

The save prints:

```text theme={null}
Saving anchor-sandbox (a running sandbox's filesystems are frozen briefly); uploading and preparing it to start fast...
NAME            STATUS  TEMPLATE       SIZE           DISK SIZE  FROM         CREATED
anchor-sandbox  Ready   agent-browser  4 vCPU / 8 GB  36 GiB     anchor-prep  13:24
```

What to expect:

* **The machine is ready in seconds.** In testing, a new machine ran 3.7 seconds after the create call. The Python install took 6 seconds and the Node.js install 4.
* **The snapshot takes a few minutes.** The save took about 3.5 minutes. You do it once.
* **The install is small.** `playwright` (Python) and `playwright-core` (Node.js) are only the client library that speaks CDP. You do not run `playwright install`, because the browser lives on Anchor.
* **Python needs a virtual environment.** The machine runs Debian 13, whose system `pip` refuses to install packages outside one.
* **The free plan runs one machine at a time.** That is why the commands delete `anchor-prep` before the next step. The snapshot is kept.

## Create a locked machine from the snapshot

Create the machine your agent works on. `--secrets all` gives it the workspace's proxy Secrets, and `--allow-domain` limits where it can connect:

```bash theme={null}
instabox create --name anchor-demo --snapshot anchor-sandbox --secrets all \
  --allow-domain api.anchorbrowser.io --allow-domain connect.anchorbrowser.io
```

```text theme={null}
Creating anchor-demo: queued
  running (scheduling)
  running (copying)
  Downloading your snapshot...
  running (booting)
  succeeded
NAME         STATE    TEMPLATE       CREATED
anchor-demo  Running  agent-browser  13:28
```

The first machine from a new snapshot took about 1 minute 50 seconds, most of it downloading the snapshot.

![InstaBox dashboard listing the anchor-demo machine as Running, created from the anchor-sandbox snapshot, with 4 vCPU, 8 GiB memory and a 20 GiB disk](https://mintcdn.com/anchor-b3ec2715/eYinnaSf6G30CyB8/images/integrations/instabox/machines.png?fit=max\&auto=format\&n=eYinnaSf6G30CyB8\&q=85\&s=12d3fa9581578f4f11ef3fa17ba3ad3f)

Check the policy and the Secret:

```bash theme={null}
instabox network anchor-demo
instabox secrets show anchor-demo
```

```text theme={null}
anchor-demo: outbound restricted to domains api.anchorbrowser.io, connect.anchorbrowser.io
```

```text theme={null}
Selection: "all"
Proxy: applied (revision 7, acknowledged 7); lease expires 2026-12-03T13:55:52Z
Delivery in the box: applied (revision 7, applied 7)
Usage ANCHORBROWSER_API_KEY: 0 requests, 0 denied (last injected never)
NAME                   DELIVERY  HOSTS                 VERSION  BYTES
ANCHORBROWSER_API_KEY  proxy     api.anchorbrowser.io  1        35
```

> [!NOTE]
>
> The InstaBox SDKs create machines, but they do not take a Secret selection or a network policy at create. Create the machine with the CLI, as above, and use the SDK to run code on it.

## The key stays out of the machine

Inside the machine the variable holds a placeholder that starts with `ibsec_`, not your key:

```bash theme={null}
instabox exec anchor-demo -- 'echo $ANCHORBROWSER_API_KEY | cut -c1-6'
```

```text theme={null}
ibsec_
```

Send the placeholder in Anchor's usual header. The proxy replaces it with the real key on the way out:

```bash theme={null}
instabox exec anchor-demo -- 'curl -s https://api.anchorbrowser.io/v1/sessions/all/status -H "anchor-api-key: $ANCHORBROWSER_API_KEY"'
```

```json theme={null}
{"data":{"count":0,"items":[]}}
```

So `curl`, the SDKs and MCP clients on the machine all authenticate without holding the key, and an agent that prints its environment or reads its config files cannot leak it. The key is not in the snapshot either.

The `cdp_url` a session returns carries no API key. It holds a session ID and a session token, which is why `connect.anchorbrowser.io` needs no Secret.

## Run a web task on the machine

Describe the goal in plain English and let Anchor's agent drive the browser. The script writes a small program to the machine and runs it there.

```python run_task.py theme={null}
from instabox import Client

TASK = '''
from anchorbrowser import Anchorbrowser

client = Anchorbrowser()
session = client.sessions.create_session()
try:
    result = client.agent.task(
        "Go to books.toscrape.com and return the title and price of the first three books",
        session_id=session.data.id,
    )
    print(result.data.result)
finally:
    client.sessions.delete_session(session.data.id)
    print("anchor session ended")
'''

client = Client()
box = client.machines.ensure_running("anchor-demo")

client.files.write(box.id, "task.py", TASK)
r = client.machines.exec(box.id, "~/anchor-env/bin/python task.py", timeout=300)
print(r.stdout, end="")
if r.stderr:
    print("stderr:", r.stderr)
print("exit code:", r.exit_code)
```

```typescript run_task.ts theme={null}
import { Sandbox } from "@insforge/instabox-sdk";

const TASK = `
import { client, agentTask, Sessions } from "anchorbrowser";

client.setConfig({ auth: () => process.env.ANCHORBROWSER_API_KEY });

const session = await Sessions.createSession();
try {
  const result = await agentTask(
    "Go to books.toscrape.com and return the title and price of the first three books",
    { sessionId: session.data.id }
  );
  console.log(result.data.result);
} finally {
  await Sessions.deleteSession({ path: { session_id: session.data.id } });
  console.log("anchor session ended");
}
`;

const sbx = await Sandbox.connect("anchor-demo");

await sbx.files.write("/data/home/anchor/task.mjs", TASK);
const r = await sbx.commands.exec("node task.mjs", {
  cwd: "/data/home/anchor",
  timeoutMs: 300_000,
});
console.log(r.stdout);
if (r.stderr) console.log("stderr:", r.stderr);
console.log("exit code:", r.exitCode);
```

```bash Python theme={null}
python run_task.py
```

```bash TypeScript theme={null}
npx tsx run_task.ts
```

Both print:

```text theme={null}
1. A Light in the Attic — £51.77
2. Tipping the Velvet — £53.74
3. Soumission — £50.10
anchor session ended
exit code: 0
```

What the script relies on:

* **The machine wakes up by itself.** An idle machine pauses after 30 minutes. `ensure_running` and `Sandbox.connect` resume it.
* **Home is `/data/home`.** The Python SDK writes relative paths there. The TypeScript version runs in `/data/home/anchor`, where `npm` installed the packages.
* **The session is created first.** The task runs on a session the script created, so `finally` can always end it, also when the task fails.
* **`Anchorbrowser()` takes no key.** It reads the placeholder from the environment and the proxy does the rest.

## Drive the browser yourself with Playwright

For step-by-step control, create an Anchor session and connect Playwright to it over CDP from the machine.

```python run_playwright.py theme={null}
from instabox import Client

SCRIPT = '''
from anchorbrowser import Anchorbrowser
from playwright.sync_api import sync_playwright

client = Anchorbrowser()
session = client.sessions.create_session(
    session={"timeout": {"max_duration": 10, "idle_timeout": 3}}
)
print("live view:", session.data.live_view_url)

try:
    with sync_playwright() as p:
        browser = p.chromium.connect_over_cdp(session.data.cdp_url)
        context = browser.contexts[0]
        page = context.pages[0] if context.pages else context.new_page()
        page.goto("https://books.toscrape.com")
        print("title:", page.title())
        print("first book:", page.get_attribute("article.product_pod h3 a", "title"))
        browser.close()
finally:
    client.sessions.delete_session(session.data.id)
    print("anchor session ended")
'''

client = Client()
box = client.machines.ensure_running("anchor-demo")

client.files.write(box.id, "browse.py", SCRIPT)
r = client.machines.exec(box.id, "~/anchor-env/bin/python browse.py", timeout=300)
print(r.stdout, end="")
if r.stderr:
    print("stderr:", r.stderr)
print("exit code:", r.exit_code)
```

```typescript run_playwright.ts theme={null}
import { Sandbox } from "@insforge/instabox-sdk";

const SCRIPT = `
import { client, Sessions } from "anchorbrowser";
import { chromium } from "playwright-core";

client.setConfig({ auth: () => process.env.ANCHORBROWSER_API_KEY });

const session = await Sessions.createSession({
  body: { session: { timeout: { max_duration: 10, idle_timeout: 3 } } },
});
console.log("live view:", session.data.live_view_url);

try {
  const browser = await chromium.connectOverCDP(session.data.cdp_url);
  const context = browser.contexts()[0];
  const page = context.pages()[0] ?? (await context.newPage());
  await page.goto("https://books.toscrape.com");
  console.log("title:", await page.title());
  console.log(
    "first book:",
    await page.getAttribute("article.product_pod h3 a", "title")
  );
  await browser.close();
} finally {
  await Sessions.deleteSession({ path: { session_id: session.data.id } });
  console.log("anchor session ended");
}
`;

const sbx = await Sandbox.connect("anchor-demo");

await sbx.files.write("/data/home/anchor/browse.mjs", SCRIPT);
const r = await sbx.commands.exec("node browse.mjs", {
  cwd: "/data/home/anchor",
  timeoutMs: 300_000,
});
console.log(r.stdout);
if (r.stderr) console.log("stderr:", r.stderr);
console.log("exit code:", r.exitCode);
```

Both print:

```text theme={null}
live view: https://live.anchorbrowser.io/inspector.html?sessionId=<session-id>&rt=<token>
title: All products | Books to Scrape - Sandbox
first book: A Light in the Attic
anchor session ended
exit code: 0
```

> [!WARNING]
>
> `session.data.cdp_url` and the live view URL carry a session token (`rt`). Anyone who has one of them can reach that browser until the session ends. Do not write them to logs you share.

### Watch the browser

Open the `live view` URL in your own browser while the script runs, or open the session in the [Anchor dashboard](https://app.anchorbrowser.io). This is the Anchor session streaming directly, so the machine needs no desktop, tunnel or public port for it.

![Anchor dashboard showing a running session with the live browser on Books to Scrape and its network requests, opened by a script inside an InstaBox machine](https://mintcdn.com/anchor-b3ec2715/eYinnaSf6G30CyB8/images/integrations/instabox/anchor-session.png?fit=max\&auto=format\&n=eYinnaSf6G30CyB8\&q=85\&s=30793ee5f6efb3f34eb091f0154eebc8)

The machine itself has a terminal and a desktop in the InstaBox dashboard:

![InstaBox dashboard for the anchor-demo machine, with a terminal on the left and the machine's desktop on the right](https://mintcdn.com/anchor-b3ec2715/eYinnaSf6G30CyB8/images/integrations/instabox/machine.png?fit=max\&auto=format\&n=eYinnaSf6G30CyB8\&q=85\&s=5063ff1c10cd399b9f9a9ec9cec1211a)

## What the allowlist blocks

The machine reaches Anchor and nothing else. A name that is not on the list does not resolve:

```bash theme={null}
instabox exec anchor-demo -- 'curl -s -m 10 https://example.org; echo "curl exit: $?"'
```

```text theme={null}
curl exit: 6
```

Exit code 6 is curl's "could not resolve host". The agent's code can still browse any site, because the page loads happen in Anchor's browser, not on the machine. This is the main reason to pair the two: the agent's code is boxed in, and all web access goes through one browser you can watch and record.

| Host | Used for |
| - | - |
| `api.anchorbrowser.io` | Creating and ending sessions, running tasks, the hosted MCP servers. The proxy adds the key here. |
| `connect.anchorbrowser.io` | The CDP websocket Playwright connects to. No key is added. |

`live.anchorbrowser.io` is opened by the person watching, not by the machine, so it does not need to be on the list.

To install more packages later, open the network, install, and lock it again. Both changes take effect at once:

```bash theme={null}
instabox network anchor-demo --open-outbound
instabox network anchor-demo --allow-domain api.anchorbrowser.io --allow-domain connect.anchorbrowser.io
```

```text theme={null}
In force now, without a restart. Connections the new policy does not allow were closed.
```

## Give the coding agents on the machine Anchor's MCP server

The default template has Claude Code, Codex and OpenCode installed. Register Anchor's hosted MCP server once, with the placeholder in the header:

```bash theme={null}
instabox exec anchor-demo -- 'claude mcp add --scope user --transport http anchor https://api.anchorbrowser.io/v1/mcp --header "anchor-api-key: $ANCHORBROWSER_API_KEY"'

instabox exec anchor-demo -- 'claude mcp list'
```

```text theme={null}
anchor: https://api.anchorbrowser.io/v1/mcp (HTTP) - ✔ Connected
```

Claude Code's config on the machine stores the placeholder, not the key. See the [MCP server](https://docs.anchorbrowser.io/advanced/mcp.md) page for the tools it offers.

## Clean up two lifecycles

There are two things to end, and ending one does not end the other.

* **The Anchor session.** End it in a `finally` block inside the script that runs on the machine. Pausing or deleting the machine does not end a cloud browser; it keeps running and billing until its own timeout.
* **The InstaBox machine.** It pauses by itself after 30 idle minutes. Delete it with `instabox rm --yes anchor-demo` when you are done. The snapshot stays until you delete it with `instabox snapshot rm anchor-sandbox --yes`.
* Set Anchor's `timeout.max_duration` and `timeout.idle_timeout`, in minutes, as a safety net for a machine that stops mid-run. See [Session Timeout](https://docs.anchorbrowser.io/advanced/session-timeout.md).
* Reuse one Anchor session for a whole agent run instead of creating one per page.

To confirm no browser is left running, ask Anchor from the machine:

```bash theme={null}
instabox exec anchor-demo -- 'curl -s https://api.anchorbrowser.io/v1/sessions/all/status -H "anchor-api-key: $ANCHORBROWSER_API_KEY"'
```

`instabox secrets show anchor-demo` also counts how many requests the proxy added the key to. After the runs on this page it read `10 requests, 0 denied`.

## API key

Each customer brings their own Anchor key as an Org Secret of their InstaBox workspace. Anchor bills them directly for browser usage; InstaBox bills for the machine.

## Troubleshooting

* **`403 missing_scope` when you save the Secret:** you are using an API key of a personal workspace. Sign in with `instabox login` and run `instabox secrets set` again.
* **`401` from Anchor on the machine:** the machine has no Secret selected, or the Secret has another name. Run `instabox secrets show anchor-demo`. Create the machine with `--secrets all`, and save the Secret as `ANCHORBROWSER_API_KEY`.
* **`error: externally-managed-environment` from `pip`:** Debian's system Python refuses installs outside a virtual environment. Create one with `python3 -m venv ~/anchor-env`, as the setup does.
* **`pip` or `npm` cannot resolve its registry:** the allowlist blocks it. Open the network, install, and lock it again, as shown in [What the allowlist blocks](#what-the-allowlist-blocks). Better, install in the snapshot.
* **The command stops after 60 seconds:** that is the default command timeout. Pass `timeout` (Python) or `timeoutMs` (TypeScript), as the samples do. A web task can take a few minutes.

See the [Sandboxes overview](https://docs.anchorbrowser.io/integrations/sandboxes) and [Create a Session](https://docs.anchorbrowser.io/quickstart/create-session.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.