> ## 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.

# Docker Sandboxes

> Give a coding agent in a Docker Sandbox an Anchor cloud browser with one kit. The API key stays on your machine.

[Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) run a coding agent such as Claude Code or Codex in an isolated environment on your machine, with a network policy and a proxy in front of it. The Anchor kit adds a cloud browser to that sandbox: three hosted MCP servers, two agent skills, and API access that never puts your key inside the sandbox.

> [card] [Install in a click](https://hub.docker.com/r/sbx/anchorbrowser)
>
> Open the `sbx/anchorbrowser` kit on Docker Hub and copy the run command under **Apply this mixin to a sandbox**.

Or paste the direct kit link into your terminal. Store your key first, as shown in [Before you start](#before-you-start).

```bash theme={null}
sbx run --kit docker.io/sbx/anchorbrowser:latest claude
```

The kit is published on Docker Hub as [`sbx/anchorbrowser`](https://hub.docker.com/r/sbx/anchorbrowser).

![Docker Hub page for the sbx/anchorbrowser Sandbox Kit, a mixin from a verified publisher](https://mintcdn.com/anchor-b3ec2715/qmpbaN4VEqWa7WlS/images/integrations/docker/docker-hub-kit.png?fit=max\&auto=format\&n=qmpbaN4VEqWa7WlS\&q=85\&s=864713914d75bf2ec8f7ffde50b6b88a)

Tested with `sbx` 0.55.0, kit 0.1.0, Claude Code 2.1.335, Codex 0.173.0, the Anchor Python SDK 1.0.1 and the Anchor TypeScript SDK 1.0.0.

## What you're integrating

**Anchor kit in a Docker Sandbox → Anchor Cloud.** The agent and its code run in the sandbox. Chromium runs as a managed Anchor cloud session, reached over HTTPS and CDP.

* Docker Sandboxes stay the agent runtime: the agent edits files, installs packages and runs commands there.
* Anchor stays the remote browser: stealth, proxies, live view and session lifecycle.
* Do not launch a browser inside the sandbox.

What the kit sets up:

| Piece | What it does |
| - | - |
| Credential | Tells the sandbox proxy to add your Anchor key to requests to `api.anchorbrowser.io`. The sandbox only ever sees a placeholder. |
| Network policy | Allows the hosts Anchor needs. Everything else stays behind the sandbox's default policy. |
| MCP servers | Registers Anchor's three hosted servers with Claude Code and Codex. |
| Skills | An SDK guide and an MCP tool guide the agent can read. |
| `anchorbrowser-smoke` | A command that checks the whole path from inside the sandbox. |

## Before you start

Install the `sbx` CLI. On macOS, use Homebrew. For Windows and Linux, follow the [Docker Sandboxes docs](https://docs.docker.com/ai/sandboxes/).

```bash theme={null}
brew install docker/tap/sbx
```

Create an Anchor key at [API Keys](https://app.anchorbrowser.io/api-keys) and store it once in the Docker Sandboxes secret store on your machine:

```bash theme={null}
sbx secret set anchorbrowser
```

Paste the key at the `Enter secret:` prompt. In a script, pipe it in instead:

```bash theme={null}
echo "$ANCHORBROWSER_API_KEY" | sbx secret set anchorbrowser
```

To check it is there:

```bash theme={null}
sbx secret ls
```

```text theme={null}
SCOPE      TYPE      NAME            SECRET
(global)   service   anchorbrowser   (stored)
```

To use a different Anchor key for one sandbox, store it with `--sandbox` after you create that sandbox. It takes priority over the global one there:

```bash theme={null}
sbx secret set anchorbrowser --sandbox anchor-demo
```

```text theme={null}
Applied secret to sandbox anchor-demo
Saved secret anchorbrowser (anchor-demo)
```

## Create a sandbox with the kit

Pass the kit with `--kit` when you start the agent. Run this from your project folder:

```bash theme={null}
sbx run --kit docker.io/sbx/anchorbrowser:latest --name anchor-demo claude
```

Swap `claude` for `codex` or `shell`. The kit picks up the stored `anchorbrowser` secret on its own.

To create the sandbox without attaching to the agent, use `sbx create` with the same flags and a workspace path:

```bash theme={null}
sbx create --kit docker.io/sbx/anchorbrowser:latest --name anchor-demo claude .
```

```text theme={null}
    loading kit image docker.io/sbx/anchorbrowser:latest
  ✓ assembled kit image (5 layers)
    setting 2 environment variables
      +ANCHORBROWSER_API_KEY +ANCHORBROWSER_MCP
    running 1 install command
      ✓ Register Anchor's hosted MCP servers with the agent (kit=anchorbrowser, user=1000, 782ms)
    registering 3 startup commands, run on every container start
      ○ Update apt package cache in background (kit=claude, background, user=0)
      ○ Register the sandbox MCP gateway (startup fallback) (kit=claude, user=agent)
      ○ Keep Anchor's hosted MCP servers registered with the agent (kit=anchorbrowser, user=1000)

  ✓ Created sandbox anchor-demo
```

> [!WARNING]
>
> Add the kit when you create the sandbox. `sbx kit add` cannot attach it to a sandbox that already exists, because the kit declares a credential. It stops with `kit "anchorbrowser" declares credentials, which the kit-add recreate flow does not yet wire`. Remove the sandbox and create it again with `--kit`.

## Check that it works

Run the smoke test inside the sandbox:

```bash theme={null}
sbx exec anchor-demo anchorbrowser-smoke
```

```text theme={null}
PASS  skills are readable under /usr/share/anchorbrowser/skills
PASS  ANCHORBROWSER_API_KEY is set (value not shown)
PASS  API reachable and key accepted (HTTP 200, 0 sessions running)
PASS  session created in 2s
INFO  cdp_url carries no apiKey parameter
PASS  CDP websocket upgrade accepted on connect.anchorbrowser.io
PASS  session readable (HTTP 200)
PASS  hosted MCP initialize accepted (HTTP 200)
PASS  session ended (HTTP 200)
PASS  running session count is back to 0

9 passed, 0 failed, 0 warnings
```

It confirms the key is accepted, creates a session, opens the CDP websocket, calls the hosted MCP endpoint, then ends the session and checks nothing is left running.

## The key stays on your machine

Inside the sandbox the variable holds a placeholder, not your key:

```bash theme={null}
sbx exec anchor-demo bash -lc 'echo $ANCHORBROWSER_API_KEY'
```

```text theme={null}
proxy-managed
```

The sandbox proxy adds the real `anchor-api-key` header to every request to `api.anchorbrowser.io`. So `curl`, the SDKs and the MCP clients all authenticate without holding the key, and an agent that prints its environment or reads its config files cannot leak it.

The `cdp_url` a session returns inside the sandbox carries no API key either.

## Use Anchor from the agent with MCP

The kit registers three hosted servers:

| Server | URL | Use it for |
| - | - | - |
| `anchor` | `https://api.anchorbrowser.io/v1/mcp` | Web tasks, sessions, logins |
| `anchor-browser` | `https://api.anchorbrowser.io/v1/mcp/browser` | Step-by-step control of a live browser |
| `anchor-actions` | `https://api.anchorbrowser.io/v1/mcp/actions` | Ready-made actions for specific sites |

> [tab] Claude Code
>
> ```bash theme={null}
> sbx exec anchor-demo claude mcp list
> ```
>
> ```text theme={null}
> mcp-gateway: http://mcp-gateway.docker.internal/mcp (HTTP) - ✔ Connected
> anchor: https://api.anchorbrowser.io/v1/mcp (HTTP) - ✔ Connected
> anchor-browser: https://api.anchorbrowser.io/v1/mcp/browser (HTTP) - ✔ Connected
> anchor-actions: https://api.anchorbrowser.io/v1/mcp/actions (HTTP) - ✔ Connected
> ```
>
> The two skills are linked into `~/.claude/skills` as `anchorbrowser` and `anchorbrowser-mcp`.

> [tab] Codex
>
> The servers are written to `~/.codex/config.toml`:
>
> ```toml theme={null}
> [mcp_servers.anchor]
> url = "https://api.anchorbrowser.io/v1/mcp"
>
> [mcp_servers.anchor-browser]
> url = "https://api.anchorbrowser.io/v1/mcp/browser"
>
> [mcp_servers.anchor-actions]
> url = "https://api.anchorbrowser.io/v1/mcp/actions"
> ```
>
> ```bash theme={null}
> sbx exec anchor-demo codex mcp list
> ```
>
> ```text theme={null}
> Name            Url                                          Bearer Token Env Var  Status   Auth
> anchor          https://api.anchorbrowser.io/v1/mcp          -                     enabled  Unknown
> anchor-actions  https://api.anchorbrowser.io/v1/mcp/actions  -                     enabled  Unknown
> anchor-browser  https://api.anchorbrowser.io/v1/mcp/browser  -                     enabled  Unknown
> mcp-gateway     http://mcp-gateway.docker.internal/mcp       -                     enabled  Bearer token
> ```

> [tab] Other agents
>
> The kit registers the servers for Claude Code and Codex. For another agent, add the three URLs above to its MCP config by hand. No header is needed, because the proxy supplies the key.

No header and no placeholder are stored in the agent's config. The registration runs when the sandbox is created and again on every start. The `anchor` server lists 29 tools from inside the sandbox, among them `perform_web_task` and `get_web_task_status`.

Then ask the agent in plain English, for example:

```text theme={null}
Use Anchor to open books.toscrape.com and return the title and price of the first three books. End the browser session when you are done.
```

Claude Code in the sandbox, answering that prompt through the `anchor` server and ending its session:

![Claude Code in a Docker Sandbox returning the title and price of the first three books and confirming the browser session is ended](https://mintcdn.com/anchor-b3ec2715/qmpbaN4VEqWa7WlS/images/integrations/docker/claude-code-result.png?fit=max\&auto=format\&n=qmpbaN4VEqWa7WlS\&q=85\&s=ea7f7f67506bb0d96b610238746d75f9)

Start with the `anchor` server. Its `perform_web_task` tool runs the whole task on Anchor's side and is the shortest path to a result.

The agent itself still needs its own login inside the sandbox. If Claude Code answers `Not logged in`, sign in with `/login`, or store its key on your machine with `sbx secret set anthropic`.

## Call the REST API

`curl` works with no header:

```bash theme={null}
sbx exec anchor-demo curl -s https://api.anchorbrowser.io/v1/sessions/all/status
```

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

## Use the Python SDK

Docker's `claude`, `codex` and `shell` sandboxes ship Python and `pip`. Install the SDK in the sandbox:

```bash theme={null}
sbx exec anchor-demo pip install --user anchorbrowser
```

`Anchorbrowser()` takes no key: it reads the placeholder from the environment and the proxy does the rest.

### Run a web task

This version creates a session, runs the task on Anchor's side, and ends the session. It needs nothing beyond the SDK.

```python task.py theme={null}
from anchorbrowser import Anchorbrowser

client = Anchorbrowser()
session = client.sessions.create_session()
try:
    result = client.tools.perform_web_task(
        session_id=session.data.id,
        prompt="Return the title and price of the first three books",
        url="https://books.toscrape.com",
    )
    print(result.data.result)
finally:
    client.sessions.delete_session(session.data.id)
    print("anchor session ended")
```

```bash theme={null}
sbx exec anchor-demo python3 task.py
```

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

### Drive the browser with Playwright

`client.agent.task(...)` and Playwright both start Playwright's local driver, which needs the `libatomic1` system library. The stock sandbox images do not include it, and the driver stops with `Connection closed while reading from the driver`. Install it once as root:

```bash theme={null}
sbx exec -u root anchor-demo bash -c "apt-get update -q; apt-get install -y -q libatomic1"
```

After that both work. Create the session yourself and pass it in, so `finally` can always end it:

```python agent_task.py theme={null}
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")
```

```python pw.py theme={null}
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}}
)
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")
```

`agent_task.py` prints the three books, and `pw.py` prints:

```text theme={null}
title: All products | Books to Scrape - Sandbox
first book: A Light in the Attic
anchor session ended
```

> [!NOTE]
>
> Called without `session_id`, `client.agent.task(...)` starts its own browser session. If the call then fails, for example because the driver cannot start, that session keeps running and nothing in your code holds its ID. Pass a session you created, as above.

## Use the TypeScript SDK

The stock sandboxes have no Node.js. Add Docker's Playwright kit next to the Anchor kit; it brings Node.js 24:

```bash theme={null}
sbx run --kit docker.io/sbx/playwright:1.65.1-0 --kit docker.io/sbx/anchorbrowser:latest --name anchor-ts claude
```

Then install the SDK and the Playwright client in the sandbox:

```bash theme={null}
sbx exec anchor-ts bash -lc "npm init -y && npm install anchorbrowser playwright-core"
```

```javascript pw.mjs theme={null}
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 } } },
});

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");
}
```

```javascript task.mjs theme={null}
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");
}
```

```bash theme={null}
sbx exec anchor-ts node pw.mjs
sbx exec anchor-ts node task.mjs
```

```text theme={null}
title: All products | Books to Scrape - Sandbox
first book: A Light in the Attic
anchor session ended
```

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

## Network

The kit allows five hosts on top of the sandbox's own policy:

| Host | Used for |
| - | - |
| `api.anchorbrowser.io` | REST API and hosted MCP servers. The proxy adds the key here. |
| `connect.anchorbrowser.io` | The CDP websocket. No key is added. |
| `pypi.org`, `files.pythonhosted.org` | Installing the Python SDK |
| `registry.npmjs.org` | Installing the TypeScript SDK |

`live.anchorbrowser.io` is left out on purpose. You open the live view in your own browser, not from the sandbox.

The agent can still browse any site, because pages load in Anchor's browser. A direct request from the sandbox to a host that is not allowed is held for your approval:

```bash theme={null}
sbx exec anchor-demo curl -s https://example.org
```

```text theme={null}
Approval required for example.org:443.

Review and respond with:
  sbx policy approval ls
```

See what a sandbox is allowed to reach with `sbx policy ls anchor-demo`.

## Leave the agent's MCP config alone

To get the credential, network policy, skills and smoke test without registering the MCP servers, pass `mcp=none`:

```bash theme={null}
sbx run --kit docker.io/sbx/anchorbrowser:latest --kit-arg mcp=none claude
```

`claude mcp list` then shows only the sandbox's own gateway:

```text theme={null}
mcp-gateway: http://mcp-gateway.docker.internal/mcp (HTTP) - ✔ Connected
```

## Clean up

* **Anchor sessions.** End every session in a `finally` block. Removing the sandbox does not end a cloud browser; it keeps running and billing until its own timeout. Check with `sbx exec anchor-demo curl -s https://api.anchorbrowser.io/v1/sessions/all/status`.
* **The sandbox.** `sbx stop anchor-demo` stops it; `sbx rm anchor-demo` removes it.
* **The key.** `sbx secret rm anchorbrowser` removes it from your machine. The kit writes nothing else to the host.

## Troubleshooting

* **`anchorbrowser-smoke: command not found`:** the sandbox was created without the kit. Remove it and create it again with `--kit docker.io/sbx/anchorbrowser:latest`.
* **`kit "anchorbrowser" declares credentials, which the kit-add recreate flow does not yet wire`:** you ran `sbx kit add` on an existing sandbox. Create a new sandbox with `--kit` instead.
* **`{"error":"Invalid API Key"}` with HTTP `401`:** the stored key is wrong. The smoke test reports it as `FAIL  GET /v1/sessions/all/status returned HTTP 401`. Run `sbx secret ls`, look for a sandbox-scoped `anchorbrowser` entry that overrides the global one, and store the right key again with `sbx secret set anchorbrowser`. Remove a sandbox-scoped one with `sbx secret rm anchorbrowser --sandbox anchor-demo`.
* **`Connection closed while reading from the driver` in Python:** Playwright's driver needs `libatomic1`. Install it as shown in [Drive the browser with Playwright](#drive-the-browser-with-playwright), or use `perform_web_task`.
* **`node: command not found`:** the stock images have no Node.js. Add the Playwright kit as shown in [Use the TypeScript SDK](#use-the-typescript-sdk).
* **`Approval required for <host>`:** the sandbox tried to reach a host outside its policy. Review it with `sbx policy approval ls`.
* **Claude Code says `Not logged in`:** the agent needs its own login in the sandbox. Use `/login` or `sbx secret set anthropic`.

The kit source is in [docker/sbx-kits-contrib](https://github.com/docker/sbx-kits-contrib/tree/v3/anchorbrowser). See the [Sandboxes overview](https://docs.anchorbrowser.io/integrations/sandboxes) and the [MCP server](https://docs.anchorbrowser.io/advanced/mcp.md) page.


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