> ## 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 provides cloud browsers for AI agents and automation: stealth browsing with residential proxies, managed authentication into third-party web apps, and browser sessions that run reliably at scale. AI agents that need Anchor credentials should start with https://docs.anchorbrowser.io/quickstart/agent-access. This flow lets agents obtain an API key programmatically without creating a dashboard account. Read that page before attempting authentication or API access.

# Daytona

> Run agent code in a Daytona sandbox and connect it to an Anchor cloud browser.

[Daytona](https://www.daytona.io) sandboxes are isolated environments for running agent or automation code.

## What you're integrating

**Anchor SDK in Daytona's base image → Anchor Cloud.** The sandbox stays vanilla and lightweight. Chromium runs as a managed Anchor cloud session; the sandbox just holds the SDK and talks to it over HTTPS + CDP.

* Daytona stays the code runtime — install packages, run a script, call a model.
* Anchor stays the remote browser — stealth, proxies, live view, and session lifecycle.
* Do not use Daytona's local browser.

## Preinstall the SDK

Install into the image app directory — not globally. `npm install -g` is not importable from user projects.

<CodeGroup>
  ```bash Python theme={null}
  pip install "anchorbrowser>=1.0" playwright
  ```

  ```bash Node.js theme={null}
  npm install anchorbrowser playwright-core
  ```
</CodeGroup>

`playwright` / `playwright-core` are only needed for direct CDP control, not for `agent.task` / `agentTask`.

Alias the env var the raw SDK actually reads, so code that does not call `setConfig` / `api_key=` still works:

```bash theme={null}
ANCHORBROWSER_API_KEY=${ANCHOR_API_KEY}
```

Put that on a Dockerfile `ENV` line or in the sandbox entrypoint. Without this alias, session and task calls fail auth (401) even when `ANCHOR_API_KEY` is set.

## API key (BYOK)

Each Daytona customer brings their own Anchor API key as a sandbox secret: `ANCHOR_API_KEY=sk-...`. List it in Daytona's secrets UI as a known integration.

Anchor bills the customer directly on usage — Daytona does not meter or bill browser usage.

<Note>
  **Keyless trial (optional):** agents without a key can self-provision a small trial key via [Agent Access](/quickstart/agent-access) — guide → puzzle challenge (120s TTL) → submit the answer for an `api_key`, sent as header `anchor-api-key`. Trial keys are capped (1 credit, 60-minute session cap). Fine for exploration, not a BYOK replacement. Do not market this as unlimited browser access.
</Note>

## Expose a browser tool

Wrap the SDK so agents call it declaratively. `agent.task` (Python) / `agentTask` (Node) return an object; the result string is `result.data.result`.

<CodeGroup>
  ```javascript Node.js theme={null}
  import { client, agentTask } from 'anchorbrowser';

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

  const result = await agentTask(
    'Go to example.com and return the page title'
  );

  console.log(result.data.result);
  ```

  ```python Python theme={null}
  import os
  from anchorbrowser import Anchorbrowser

  anchor_client = Anchorbrowser(api_key=os.getenv('ANCHORBROWSER_API_KEY'))

  result = anchor_client.agent.task(
      'Go to example.com and return the page title'
  )

  print(result.data.result)
  ```
</CodeGroup>

### Optional: full Playwright control

Connect over CDP to the created cloud session (`session.data.cdp_url`). You can create the session outside the sandbox and pass the URL in (for example as `ANCHOR_CDP_URL`), or create it from inside the sandbox.

<Warning>
  That URL carries the API key in the query string — **never log it**. Surface `session.data.live_view_url` to humans instead (`https://live.anchorbrowser.io/inspector.html?sessionId=...`). Closing Playwright only disconnects — it does not end the cloud session.
</Warning>

<CodeGroup>
  ```javascript Playwright theme={null}
  import { chromium } from 'playwright-core';
  import { client, Sessions } from 'anchorbrowser';

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

  const session = await Sessions.createSession({
    body: {
      session: {
        timeout: { max_duration: 30, idle_timeout: 10 },
      },
    },
  });

  const browser = await chromium.connectOverCDP(
    process.env.ANCHOR_CDP_URL ?? session.data.cdp_url
  );
  const page = browser.contexts()[0].pages()[0] ?? await browser.newPage();
  await page.goto('https://example.com');
  console.log('Title:', await page.title());
  await browser.close();

  await Sessions.deleteSession({ path: { session_id: session.data.id } });
  ```

  ```python Playwright theme={null}
  import os
  from anchorbrowser import Anchorbrowser
  from playwright.sync_api import sync_playwright

  anchor_client = Anchorbrowser(api_key=os.getenv('ANCHORBROWSER_API_KEY'))
  session = anchor_client.sessions.create_session(
      session={'timeout': {'max_duration': 30, 'idle_timeout': 10}}
  )
  cdp_url = os.getenv('ANCHOR_CDP_URL') or session.data.cdp_url

  with sync_playwright() as p:
      browser = p.chromium.connect_over_cdp(cdp_url)
      page = browser.contexts[0].pages[0] if browser.contexts[0].pages else browser.new_page()
      page.goto('https://example.com')
      print('Title:', page.title())
      browser.close()

  anchor_client.sessions.delete_session(session.data.id)
  ```
</CodeGroup>

## Session hygiene

* Reuse **one** session per agent run — do not create a session per page.
* Set `timeout.max_duration` / `timeout.idle_timeout` (minutes) so abandoned sandboxes do not hold browsers open. See [Session Timeout](/advanced/session-timeout).
* Delete the session on sandbox teardown (`delete_session` / `deleteSession`).
* Show `live_view_url` in the sandbox UI so users can watch the browser run. That stream is the remote Anchor session, not Daytona's sandbox desktop view.

## Egress

If Daytona sandboxes restrict egress, allowlist:

* `https://api.anchorbrowser.io`
* `wss://connect.anchorbrowser.io`
* `https://live.anchorbrowser.io`

See the [Sandboxes overview](/integrations/sandboxes) and [Create a Session](/quickstart/create-session).
