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

> ## Agent Instructions
> Authenticate REST, SDK, and CLI requests with the `x-api-key` header using the `HYPERBROWSER_API_KEY` environment variable (create keys at https://app.hyperbrowser.ai).
> Always stop browser sessions (`sessions.stop(id)` / `PUT /api/session/{id}/stop`) and sandboxes (`sandboxes.stop(id)` / `PUT /api/sandbox/{id}/stop`) in `try`/`finally` blocks to avoid idle billing.
> Choose the right surface: use Web API (`/api/web/fetch`, `batch-fetch`, `crawl`, `search`) for stateless reading and extraction (prefer it over legacy `/api/scrape`); Browser Sessions (`/api/session`) for interactive, authenticated, or Playwright/Puppeteer workflows; Cloud Agents (`/api/task/*`) for autonomous browser tasks; and Sandboxes (`/api/sandbox`) for isolated Linux or macOS code execution.
> Use `@hyperbrowser/sdk` for Node.js/TypeScript, `hyperbrowser` 1.0+ typed-dict request params for Python (avoid legacy Pydantic request classes), the unified `hx` CLI for terminal workflows, and hosted OAuth MCP at `https://mcp.hyperbrowser.ai/mcp/web` (web tools; use `https://mcp.hyperbrowser.ai/mcp` only when browser, sandbox, admin, and usage tools are needed).

# Warm Browser Pools with Session Snapshots

> Capture a pre-warmed browser session snapshot, clone parallel workers from it, extend long runs, and monitor active capacity

When every worker needs the same heavy web application already booted and hydrated, [Browser Session Snapshots](https://hyperbrowser.ai/docs/sessions/snapshots.md) eliminate repetitive startup time by restoring live VM memory state directly via `startFromSnapshot`.

**Required API key scopes:** `browser.sessions.create`, `browser.sessions.read`, `browser.sessions.update`, `browser.sessions.stop`, `browser.sessions.snapshots.create`, `browser.sessions.logs.read`.

## Prerequisites

* `HYPERBROWSER_API_KEY` exported in your shell and team browser-snapshot access enabled.
* `@hyperbrowser/sdk` + `playwright-core` (TypeScript) or `hyperbrowser` + `playwright` (Python) installed.

> [!NOTE]
>
> Browser session snapshots require VM-backed sessions and team snapshot access. Sessions started with `webBotAuth` cannot be snapshotted. Snapshots of sessions that filled secrets are marked as containing secrets, and restoring them requires team owner/admin access or the `secrets.use` scope for API keys.

***

## Step 1: Warm Up & Capture a Snapshot

```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { chromium } from "playwright-core";

const client = new Hyperbrowser({ apiKey: process.env.HYPERBROWSER_API_KEY });

async function buildWarmSnapshot(): Promise<string> {
  const seed = await client.sessions.create({
    region: "us-central",
    enableLogCapture: true,
  });

  try {
    const browser = await chromium.connectOverCDP(seed.wsEndpoint);
    const page = browser.contexts()[0].pages()[0];
    await page.goto("https://app.example.com/workspace", { waitUntil: "networkidle" });

    const snapshot = await client.sessions.createSnapshot(seed.id);
    console.log("Captured snapshot:", snapshot.snapshotId);
    return snapshot.snapshotId;
  } finally {
    await client.sessions.stop(seed.id);
  }
}
```

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os
from hyperbrowser import Hyperbrowser
from playwright.sync_api import sync_playwright

client = Hyperbrowser(api_key=os.environ["HYPERBROWSER_API_KEY"])


def build_warm_snapshot() -> str:
    seed = client.sessions.create({
        "region": "us-central",
        "enable_log_capture": True,
    })

    try:
        with sync_playwright() as p:
            browser = p.chromium.connect_over_cdp(seed.ws_endpoint)
            page = browser.contexts[0].pages[0]
            page.goto("https://app.example.com/workspace", wait_until="networkidle")

            snapshot = client.sessions.create_snapshot(seed.id)
            print("Captured snapshot:", snapshot.snapshot_id)
            return snapshot.snapshot_id
    finally:
        client.sessions.stop(seed.id)
```

***

## Step 2: Restore Workers, Extend Long Jobs & Inspect Events

```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
async function runFromSnapshot(snapshotId: string) {
  const { activeSessionsCount } = await client.sessions.getActiveSessionsCount();
  console.log("Active sessions before launch:", activeSessionsCount);

  const worker = await client.sessions.create({
    region: "us-central", // Must match snapshot region
    startFromSnapshot: { snapshotId },
  });

  try {
    // Extend if a heavy workflow needs extra time
    await client.sessions.extendSession(worker.id, 30);

    const browser = await chromium.connectOverCDP(worker.wsEndpoint);
    const page = browser.contexts()[0].pages()[0];
    console.log("Restored URL:", page.url());

    // Inspect structured events (downloads, CAPTCHAs, credential fill)
    const events = await client.sessions.eventLogs.list(worker.id, { limit: 20 });
    console.log("Event count:", events.data.length);
  } finally {
    await client.sessions.stop(worker.id);
  }
}
```

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
def run_from_snapshot(snapshot_id: str):
    active = client.sessions.get_active_sessions_count()
    print("Active sessions before launch:", active.active_sessions_count)

    worker = client.sessions.create({
        "region": "us-central",
        "start_from_snapshot": {"snapshot_id": snapshot_id},
    })

    try:
        client.sessions.extend_session(worker.id, 30)

        with sync_playwright() as p:
            browser = p.chromium.connect_over_cdp(worker.ws_endpoint)
            page = browser.contexts[0].pages[0]
            print("Restored URL:", page.url)

        events = client.sessions.event_logs.list(worker.id, {"limit": 20})
        print("Event count:", len(events.data))
    finally:
        client.sessions.stop(worker.id)
```

## Expected output

* `buildWarmSnapshot()` logs `Captured snapshot: <snapshot-id>` and stops the seed session cleanly.
* `runFromSnapshot()` prints the current active session count, confirms the worker opens directly at `https://app.example.com/workspace`, extends the timeout by 30 minutes, and prints the session event log count.

## Next Steps

* [Browser Session Snapshots](https://hyperbrowser.ai/docs/sessions/snapshots.md) — snapshot constraints and region matching.
* [Observability & Debugging](https://hyperbrowser.ai/docs/sessions/observability.md) — event logs, recordings, and live debugging.


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