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

# Isolated CI Sandbox with Vaults & Egress Policy

> Run untrusted or AI-generated tests inside a locked-down Linux sandbox with allowlisted egress and encrypted vault secrets

This recipe launches an isolated Linux [Sandbox](https://hyperbrowser.ai/docs/sandboxes/introduction.md) with:

* **Default-deny outbound networking** (`allowInternetAccess: false`) that only permits requests to your allowlisted API domain.
* **Encrypted Vault injection** (`vault`) so a specific command receives `API_TOKEN` without persisting plaintext secrets to disk.
* **File upload and artifact download** using `sandbox.files`.

**Required API key scopes:** `sandboxes.create`, `sandboxes.read`, `sandboxes.stop`, `secrets.use`.

## Prerequisites

* `HYPERBROWSER_API_KEY` exported in your shell and a pre-created vault named `ci-secrets` exposing `API_TOKEN`.
* `@hyperbrowser/sdk` (TypeScript), `hyperbrowser` (Python), or the `hx` CLI installed.

***

## Run Locked-Down Code in a Sandbox

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

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

async function runIsolatedCheck() {
  const sandbox = await client.sandboxes.create({
    imageName: "node",
    timeoutMinutes: 10,
    allowInternetAccess: false,
    allowOut: ["api.example.com"],
  });

  try {
    await sandbox.files.writeText(
      "/tmp/check.mjs",
      `
      const res = await fetch("https://api.example.com/health", {
        headers: { Authorization: "Bearer " + process.env.API_TOKEN },
      });
      console.log(JSON.stringify({ status: res.status }));
      `.trim()
    );

    // Inject the pre-created vault only into this process
    const proc = await sandbox.processes.start("node /tmp/check.mjs", {
      vault: "ci-secrets",
    });

    const result = await proc.wait();
    console.log("Exit code:", result.exitCode, "Output:", result.stdout);
  } finally {
    await sandbox.stop();
  }
}

runIsolatedCheck().catch(console.error);
```

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

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


def run_isolated_check():
    sandbox = client.sandboxes.create({
        "image_name": "node",
        "timeout_minutes": 10,
        "allow_internet_access": False,
        "allow_out": ["api.example.com"],
    })

    try:
        sandbox.files.write_text(
            "/tmp/check.mjs",
            'const res = await fetch("https://api.example.com/health", '
            '{ headers: { Authorization: "Bearer " + process.env.API_TOKEN } });\n'
            "console.log(JSON.stringify({ status: res.status }));\n",
        )

        proc = sandbox.processes.start("node /tmp/check.mjs", vault="ci-secrets")

        result = proc.wait()
        print("Exit code:", result.exit_code, "Output:", result.stdout)
    finally:
        sandbox.stop()


if __name__ == "__main__":
    run_isolated_check()
```

```bash hx CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Equivalent workflow from your terminal
SANDBOX_ID=$(hx --json vm create node --timeout-minutes 10 \
  --allow-internet=false --allow-out api.example.com | jq -r '.data.id')

hx vm file write "$SANDBOX_ID" /tmp/check.mjs --from-stdin <<'EOF'
const res = await fetch("https://api.example.com/health", {
  headers: { Authorization: "Bearer " + process.env.API_TOKEN },
});
console.log(JSON.stringify({ status: res.status }));
EOF

hx vm exec "$SANDBOX_ID" --vault ci-secrets -- node /tmp/check.mjs
hx vm stop "$SANDBOX_ID"
```

## Expected output

* Prints `Exit code: 0 Output: {"status":200}` after the sandboxed Node process reaches `https://api.example.com/health` using the injected `API_TOKEN` while all other outbound destinations remain blocked.
* Stops the sandbox cleanly in `finally` (or via `hx vm stop`).

## Next Steps

* [Network Policies](https://hyperbrowser.ai/docs/sandboxes/networking.md) — live egress updates, CIDR rules, and domain allowlists.
* [Vaults](https://hyperbrowser.ai/docs/sandboxes/vaults.md) — group secrets and manage customer-managed key wrapping.


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