# Browser Sandbox

> A secure browser sandbox where agents can interact with the web.

import LaunchCURL from "/snippets/v2/browser/launch/curl.mdx";
import LaunchJS from "/snippets/v2/browser/launch/js.mdx";
import LaunchOutput from "/snippets/v2/browser/launch/output.mdx";
import ExecuteCURL from "/snippets/v2/browser/execute/curl.mdx";
import ExecuteCURLBash from "/snippets/v2/browser/execute/curl-bash.mdx";
import ExecuteJS from "/snippets/v2/browser/execute/js.mdx";
import ExecuteOutput from "/snippets/v2/browser/execute/output.mdx";
import CloseCURL from "/snippets/v2/browser/close/curl.mdx";
import CloseJS from "/snippets/v2/browser/close/js.mdx";
import ListCURL from "/snippets/v2/browser/list/curl.mdx";
import ListJS from "/snippets/v2/browser/list/js.mdx";
import ListOutput from "/snippets/v2/browser/list/output.mdx";
import QuickstartCURL from "/snippets/v2/browser/quickstart/curl.mdx";
import QuickstartJS from "/snippets/v2/browser/quickstart/js.mdx";
import PlaywrightJS from "/snippets/v2/browser/playwright/js.mdx";
import PlaywrightPython from "/snippets/v2/browser/playwright/python.mdx";
import QuickstartCLI from "/snippets/v2/browser/quickstart/cli.mdx";
import LaunchCLI from "/snippets/v2/browser/launch/cli.mdx";
import ExecuteCLI from "/snippets/v2/browser/execute/cli.mdx";
import ListCLI from "/snippets/v2/browser/list/cli.mdx";
import CloseCLI from "/snippets/v2/browser/close/cli.mdx";
import QuickstartPython from "/snippets/v2/browser/quickstart/python.mdx";
import PersistentCURL from "/snippets/v2/browser/persistent/curl.mdx";
import PersistentJS from "/snippets/v2/browser/persistent/js.mdx";
import PersistentPython from "/snippets/v2/browser/persistent/python.mdx";
import PersistentCLI from "/snippets/v2/browser/persistent/cli.mdx";
import LaunchPython from "/snippets/v2/browser/launch/python.mdx";
import ExecutePython from "/snippets/v2/browser/execute/python.mdx";
import ListPython from "/snippets/v2/browser/list/python.mdx";
import ClosePython from "/snippets/v2/browser/close/python.mdx";

<Info>
For agent workflows, use [Interact](/features/interact). Interact is the supported CLI/MCP path and can be driven with prompts or code after a scrape; MCP also supports opening from a URL directly.
</Info>

| Surface | Use it for | Entry point | Agent surface |
|---|---|---|---|
| Browser Sandbox | Standalone browser sessions for API/SDK users that need a sandbox, CDP URL, live view, or persistent session lifecycle | `POST /v2/interact` | API and SDKs; hidden CLI browser command is legacy |
| Interact | Acting on a scraped page; MCP can also open from a URL with `firecrawl_interact` URL mode | `POST /v2/scrape/{scrapeId}/interact`, CLI `interact` after scrape, or MCP `firecrawl_interact` | Recommended for CLI/MCP agent workflows |

Firecrawl Browser Sandbox gives API and SDK users a secure browser environment where agents can interact with the web. Fill out forms, click buttons, authenticate, and more.
No local setup, no Chromium installs, no driver compatibility issues. Agent browser and playwright are pre-installed.

Available via [API](/api-reference/endpoint/browser-create), [Node SDK](/sdks/node#browser), [Python SDK](/sdks/python#browser), and [Vercel AI SDK](/developer-guides/llm-sdks-and-frameworks/vercel-ai-sdk). The hidden `firecrawl browser` CLI command is legacy; CLI and MCP agent flows should use scrape + interact instead.

To add Interact support to an AI coding agent (Claude Code, Codex, Open Code, Cursor, etc.), install the Firecrawl skill:

```bash
npx -y firecrawl-cli@latest init --all --browser
```

Each session runs in an isolated, disposable or persistent sandbox that scales without managing infrastructure.

## Quick Start

Create a session, execute code, and close it:

<CodeGroup>

<QuickstartJS />
<QuickstartPython />
<QuickstartCLI />
<QuickstartCURL />

</CodeGroup>

- **No Driver Installation** - No Chromium binary, no `playwright install`, no driver compatibility issues
- **Python, JavaScript & Bash** - Send code via API, CLI, or SDK and get results back. All three languages run remotely in the sandbox
- **agent-browser** - Pre-installed CLI with 60+ commands. AI agents write simple bash commands instead of Playwright code
- **Playwright loaded** - Playwright comes pre-installed in the sandbox. Agents can write Playwright code if they prefer.
- **CDP Access** - Connect your own Playwright instance over WebSocket when you need full control
- **Live View** - Watch sessions in real time via embeddable stream URL
- **Interactive Live View** - Let users interact with the browser directly through an embeddable interactive stream

## Launch a Session

Returns a session ID, CDP URL, and live view URL.

<CodeGroup>

<LaunchJS />
<LaunchPython />
<LaunchCLI />
<LaunchCURL />

</CodeGroup>

<LaunchOutput />

## Execute Code

Run Python, JavaScript, or bash code in your session. Output is returned via `stdout`; for Node.js, the last expression value is also available in `result`.

<CodeGroup>

<ExecuteJS />
<ExecutePython />
<ExecuteCLI />
<ExecuteCURL />
<ExecuteCURLBash />

</CodeGroup>

<ExecuteOutput />

### Handling File Downloads

Files downloaded inside a session can be captured and returned as base64. Use Playwright's download API via the execute endpoint:

<CodeGroup>

```python Python
import base64

async with page.expect_download() as download_info:
    await page.click('a#download-link')  # Click the element that triggers the download

download = download_info.value
path = await download.path()

# Optionally save to a known path
# await download.save_as('/tmp/myfile.pdf')

# Read and output file content as base64
with open(path, "rb") as f:
    content = base64.b64encode(f.read()).decode()
    print(content)
```

```javascript Node
// Get the download URL from the link element
const href = await page.getAttribute('a#download-link', 'href');

// Fetch the file in the browser context and convert to base64
const b64 = await page.evaluate(async (url) => {
  const resp = await fetch(url);
  const blob = await resp.blob();
  return new Promise((resolve) => {
    const reader = new FileReader();
    reader.onloadend = () => resolve(reader.result.split(',')[1]);
    reader.readAsDataURL(blob);
  });
}, href);

process.stdout.write(b64);
```

</CodeGroup>

<Note>
The sandbox filesystem is ephemeral — downloaded files are lost when the session ends. To persist files, read their content within the session and save it to your own storage. Persistent profiles preserve browser state (cookies, localStorage) but not files on disk.
</Note>

## agent-browser (Bash Mode)

[agent-browser](https://github.com/vercel-labs/agent-browser) is a headless browser CLI pre-installed in every sandbox. Instead of writing Playwright code, agents send simple bash commands. The CLI auto-injects `--cdp` so agent-browser connects to your active session automatically.

<Note>
The `firecrawl browser` CLI examples below are for legacy Browser Sandbox sessions. For CLI/MCP agent workflows, prefer `firecrawl interact` or the MCP `firecrawl_interact` tool.
</Note>

### Shorthand

The fastest way to use browser. Both the shorthand and `execute` send commands to agent-browser automatically. The shorthand just skips `execute` and auto-launches a session if needed:

```bash
firecrawl browser "open https://example.com"
firecrawl browser "snapshot"
firecrawl browser "click @e5"
```

### CLI

The explicit form uses `execute`. Commands are sent to agent-browser automatically -- you don't need to type `agent-browser` or use `--bash`:

<CodeGroup>

```bash Navigate & Snapshot
firecrawl browser execute "open https://example.com"
firecrawl browser execute "snapshot"
```

```bash Interact
firecrawl browser execute "click @e5"
firecrawl browser execute "fill @e3 'search query'"
firecrawl browser execute "scrape"
```

</CodeGroup>

### API & SDK

Use `language: "bash"` to run agent-browser commands via the API or SDKs:

<CodeGroup>

```bash cURL
curl -X POST "https://api.firecrawl.dev/v2/interact/YOUR_SESSION_ID/execute" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "agent-browser snapshot",
    "language": "bash"
  }'
```

```javascript Node
const result = await app.browserExecute(sessionId, {
  code: "agent-browser snapshot",
  language: "bash",
});
```

```python Python
result = app.browser_execute(
    session_id,
    code="agent-browser snapshot",
    language="bash",
)
```

</CodeGroup>

## Session Management

### Persistent Sessions

By default, each browser session starts with a clean slate. With `profile`, you can save and reuse browser state across sessions. This is useful for staying logged in and preserving preferences.

To save or select a profile, use the `profile` parameter when creating a session.

<CodeGroup>

<PersistentJS />
<PersistentPython />
<PersistentCURL />
<PersistentCLI />

</CodeGroup>

| Parameter | Default | Description |
|-----------|---------|-------------|
| `name` | — | A name for the persistent profile. Sessions with the same name share storage. |
| `saveChanges` | `true` | When `true`, browser state is saved back to the profile on close. Set to `false` to load existing data without writing — useful when you need multiple concurrent readers. |

<Note>
Only one session can save to a profile at a time. If another session is already saving, you'll get a `409` error. You can still open the same profile with `saveChanges: false`, or try again later.
</Note>

The browser session state only saves when the session is closed. So we recommend closing the browser session when you are done with it so it can be reused. Once a session is closed, its session ID is no longer valid — you cannot reuse it. Instead, create a new session with the same profile name and use the new session ID returned in the response. To save and close it:

<CodeGroup>

<CloseJS />
<ClosePython />
<CloseCLI />
<CloseCURL />

</CodeGroup>

### List Sessions

<CodeGroup>

<ListJS />
<ListPython />
<ListCLI />
<ListCURL />

</CodeGroup>

<ListOutput />

### TTL Configuration

Sessions have two TTL controls:

| Parameter | Default | Description |
|-----------|---------|-------------|
| `ttl` | 600s (10 min) | Maximum session lifetime (30-3600s) |
| `activityTtl` | 300s (5 min) | Auto-close after inactivity (10-3600s) |

### Close a Session

<CodeGroup>

<CloseJS />
<ClosePython />
<CloseCLI />
<CloseCURL />

</CodeGroup>

## Live View

Every session returns a `liveViewUrl` in the response that you can embed to watch the browser in real time. Useful for debugging, demos, or building browser-powered UIs.

```json Response
{
  "success": true,
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "cdpUrl": "wss://browser.firecrawl.dev/cdp/550e8400...?token=abc123...",
  "liveViewUrl": "https://liveview.firecrawl.dev/...",
  "interactiveLiveViewUrl": "https://liveview.firecrawl.dev/...",
  "expiresAt": "2025-01-15T10:40:00Z"
}
```

```html
<iframe src="LIVE_VIEW_URL" width="100%" height="600" />
```

### Interactive Live View

The response also includes an `interactiveLiveViewUrl`. Unlike the standard live view which is view-only, the interactive live view allows users to click, type, and interact with the browser session directly through the embedded stream. This is useful for building user-facing browser UIs, collaborative debugging, or any scenario where the viewer needs to control the browser.

```html
<iframe src="INTERACTIVE_LIVE_VIEW_URL" width="100%" height="600" />
```

## Connecting via CDP

Every session exposes a CDP WebSocket URL. The execute API and `--bash` flag cover most use cases, but if you need full local control you can connect directly.

<CodeGroup>

<PlaywrightJS />
<PlaywrightPython />

```bash agent-browser
# Use the cdpUrl from the session response
agent-browser open https://example.com --cdp "$CDP_URL"
agent-browser snapshot --cdp "$CDP_URL"
```

</CodeGroup>

## When to Use Browser

| Use Case | Right Tool |
|----------|-----------|
| Extract content from a known URL | [Scrape](/features/scrape) |
| Search the web and get results | [Search](/features/search) |
| Navigate pagination, fill forms, click through flows | **Browser** |
| Multi-step workflows with interaction | **Browser** |
| Parallel browsing across many sites | **Browser** (each session is isolated) |

## Use Cases

- **Competitive intelligence** - Browse competitor sites, navigate search forms and filters, extract pricing and features into structured data
- **Knowledge base ingestion** - Navigate help centers, docs, and support portals that require clicks, pagination, or authentication
- **Market research** - Launch parallel browser sessions to build datasets from job boards, real estate listings, or legal databases

## Pricing

Pricing depends on how you drive the session: 7 credits per browser minute if the session uses a `prompt`, or 2 credits per browser minute if it does not (Playwright `code` only). Billing is per browser minute with a one-minute minimum. Free users get 5 hours of free usage.

## Rate limits

For the initial launch, we allow all plans up to have up to 20 concurrent browser sessions.

## API Reference

- [Create Browser Session](/api-reference/endpoint/browser-create)
- [Execute Browser Code](/api-reference/endpoint/browser-execute)
- [List Browser Sessions](/api-reference/endpoint/browser-list)
- [Delete Browser Session](/api-reference/endpoint/browser-delete)

---

Have feedback or need help? Email [help@firecrawl.com](mailto:help@firecrawl.com) or reach out on [Discord](https://discord.gg/firecrawl).

> Are you an AI agent that needs a Firecrawl API key? See [firecrawl.dev/agent-onboarding/SKILL.md](https://www.firecrawl.dev/agent-onboarding/SKILL.md) for automated onboarding instructions.
