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

# Sandboxes (hx vm)

> Create and manage Linux and macOS sandboxes, files, logs, processes, terminals, volumes, images, snapshots, and disks

Use `hx vm` (aliases: `hx sandbox`, `hx sandboxes`) to run and manage Linux and macOS sandboxes from your terminal.

***

## Create, Inspect & Stop Sandboxes

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Linux sandbox from a built-in or custom image
hx vm create node
hx vm create node --port 3000 --port 9222:auth --region us --timeout-minutes 30
hx vm create --image-name node --image-id <image-id> --port 3000 --auth --enable-recording

# Launch from a memory snapshot
hx vm create my_snapshot --snapshot
hx vm create --snapshot-name my_snapshot --snapshot-id <snapshot-id>

# Launch a macOS sandbox (Beta) or reuse a persistent disk
hx vm create --macos --region us --cpu 8 --memory 8g --timeout-minutes 60
hx vm create --disk-id <disk-id> --region us --cpu 8 --memory 8g

# List, inspect, and stop
hx vm list
hx vm list --status closed --page 1 --limit 20
hx vm get <sandbox-id>
hx vm stop <sandbox-id>
hx vm stop --all --force
```

### Verified `hx vm create` Flags

* **Target:** `--image-name`, `--image-id`, `--snapshot`, `--snapshot-name`, `--snapshot-id`, `--macos`, `--disk-id`
* **Resources & region:** `--region`, `--cpu`, `--memory`, `--disk`, `--timeout-minutes`
* **Networking, storage & recording:** `--port` (`<port>`, `<port>:auth`, `<port>:public`), `--auth`, `--mount`, `--allow-internet`, `--allow-out`, `--deny-out`, `--enable-recording`
* **Secrets (Linux):** `--secret`, `--secret-version`, `--vault`, `--1password-token`, `--1password-vault`, `--1password-field`

***

## Outbound Network & Exposed Ports

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Set outbound policy at creation or live on a running sandbox
hx vm create node --allow-internet=false --allow-out api.example.com --allow-out 1.1.1.1
hx vm network set <sandbox-id> --deny-out 203.0.113.0/24
hx vm network set <sandbox-id> --allow-internet=false --allow-out api.example.com
hx vm network clear <sandbox-id>

# Expose / unexpose ports on a running sandbox
hx vm expose <sandbox-id> --port 3000
hx vm expose <sandbox-id> --port 3000 --auth
hx vm expose <sandbox-id> --port 3000:auth
hx vm unexpose <sandbox-id> --port 3000
```

See [Network Policies](https://hyperbrowser.ai/docs/sandboxes/networking.md) for rule precedence and target formats.

***

## Run Commands & Background Processes (`hx vm exec`, `hx vm process`)

Run a one-shot command:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
hx vm exec <sandbox-id> 'pwd'
hx vm exec --cwd /tmp --env FOO=bar --timeout-ms 30000 <sandbox-id> 'echo $FOO'
```

Manage long-running background processes:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
hx vm process start <sandbox-id> 'python3 -m http.server 3000'
hx vm process list <sandbox-id> --status running --limit 20
hx vm process get <sandbox-id> <process-id>
hx vm process wait <sandbox-id> <process-id> --timeout-ms 60000
hx vm process stream <sandbox-id> <process-id> --from-seq 120 --show-seq
printf 'hello\n' | hx vm process stdin <sandbox-id> <process-id> --from-stdin --eof
hx vm process signal <sandbox-id> <process-id> --signal TERM
hx vm process kill <sandbox-id> <process-id>
```

***

## Open an Interactive Terminal

Launch an interactive shell inside a running sandbox with `hx vm connect`:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Pick an active sandbox interactively, or pass a sandbox ID
hx vm connect
hx vm connect <sandbox-id>

# Override command, working directory, env vars, or terminal dimensions
hx vm connect <sandbox-id> --command python3 --arg -i --cwd /tmp --env FOO=bar
hx vm connect <sandbox-id> --rows 40 --cols 120
```

By default, `hx vm connect` launches `/bin/bash -i -l`. Also accepts `--timeout-ms` and `--use-shell`.

***

## Filesystem Operations (`hx vm file`, `hx vm cp`, `hx vm read`)

### Copy & Read Shorthands

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Copy between local machine and sandbox (or between two sandboxes)
hx vm cp ./local.txt <sandbox-id>:/tmp/local.txt --overwrite
hx vm cp <sandbox-id>:/tmp/local.txt ./downloaded.txt
hx vm cp <sandbox-id>:/tmp/a.txt <sandbox-id>:/tmp/b.txt

# Read file contents directly (sandbox ID and path are separate arguments)
hx vm read <sandbox-id> /tmp/file.txt
hx vm read --encoding base64 --offset 0 --length 128 <sandbox-id> /tmp/file.bin
```

### Full Filesystem Subcommands (`hx vm file`)

| Command | Key Flags | Description |
| - | - | - |
| `hx vm file ls <sandbox-id> <path>` | `--depth`, `--long` | List directory entries. |
| `hx vm file exists <sandbox-id> <path>` | — | Check whether a path exists. |
| `hx vm file stat <sandbox-id> <path>` | — | Inspect size, mode, and timestamps. |
| `hx vm file cat <sandbox-id> <path>` | `--offset`, `--length`, `--encoding` | Read file contents. |
| `hx vm file write <sandbox-id> <path>` | `--data`, `--from-stdin`, `--append`, `--encoding`, `--mode` | Write or append to a file. |
| `hx vm file write-batch <sandbox-id> <manifest-path>` | — | Write multiple files from a JSON manifest. |
| `hx vm file upload <sandbox-id> <local-path> <remote-path>` | `--overwrite` | Upload a local file. |
| `hx vm file download <sandbox-id> <remote-path> <local-path>` | `--overwrite` | Download a remote file. |
| `hx vm file presign-upload <sandbox-id> <path>` | `--expires-in-seconds`, `--one-time` | Generate a presigned upload URL. |
| `hx vm file presign-download <sandbox-id> <path>` | `--expires-in-seconds`, `--one-time` | Generate a presigned download URL. |
| `hx vm file mkdir <sandbox-id> <path>` | `--parents`, `--mode` | Create a directory. |
| `hx vm file rm <sandbox-id> <path>` | `--recursive`, `--force` | Remove a file or directory (aliases: `remove`, `delete`). |
| `hx vm file mv <sandbox-id> <from> <to>` | `--overwrite` | Move or rename a path (aliases: `move`, `rename`). |
| `hx vm file cp <sandbox-id> <from> <to>` | `--recursive`, `--overwrite` | Copy a path inside the sandbox. |
| `hx vm file chmod <sandbox-id> <path> <mode>` | `--recursive` | Change file permissions. |
| `hx vm file chown <sandbox-id> <path> [uid] [gid]` | `--recursive` | Change file ownership. |
| `hx vm file watch <sandbox-id> [path]` | `--from-cursor` | Watch filesystem change events. |

***

## Read Sandbox Diagnostic Logs (`hx vm logs`)

List available diagnostic logs or read/follow a specific stream (`chrome`, `captcha`, `proxy`, `window-manager`, `vnc`, `selenium`, `ffmpeg`, `port-forward`, `xvfb`):

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
hx vm logs <sandbox-id>
hx vm logs <sandbox-id> chrome --tail 500
hx vm logs <sandbox-id> captcha --follow
hx vm logs <sandbox-id> ffmpeg --all
```

***

## Volumes, Images, Snapshots & Persistent Disks

### Volumes (`hx vm volumes`)

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
hx vm volumes create my-workspace
hx vm volumes ls --page 1 --limit 20
hx vm volumes get <volume-id>
hx vm volumes delete my-workspace --force

# Mount at creation time
hx vm create node --mount <volume-id>:/mnt/workspace
hx vm create node --mount <volume-id>:/mnt/cache:ro
```

### Custom Images (`hx vm image`)

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Remote Dockerfile build (no local Docker needed)
hx vm image build --remote ./my-app app-prod --dockerfile Dockerfile

# Export a local Docker image
hx vm image build node:22 custom_node --env NODE_ENV=production --entrypoint 'npm run start'

# Inspect, wait, cancel, list, and delete
hx vm image status <build-id>
hx vm image wait <build-id> --wait-timeout 35m --poll-interval 3s
hx vm image cancel <build-id>
hx vm image list --source team --search app
hx vm image delete <name|id> --force
```

Additional verified build flags: `--remote-full-context`, `--cpu`, `--memory`, `--disk`, `--rootfs-disk`, `--yes`.

### Memory Snapshots (`hx vm snapshot`)

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
hx vm snapshot create <sandbox-id> my_snapshot
hx vm snapshot list --limit 20 --image-name node --status created
hx vm snapshot get <name|id>
hx vm snapshot delete <name|id> --force
```

### Persistent Mac Disks (Beta) (`hx vm disks`)

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
hx vm disks list
hx vm disks list --defaults --region us
hx vm disks list --snapshots
hx vm disks create --source <default-or-snapshot-id> --name workspace --region us
hx vm disks get <disk-id>
hx vm disks snapshot <disk-id> --name before-install
hx vm disks delete <disk-id>
```

`create` and `snapshot` also accept `--id` for idempotent retries. See [macOS Sandboxes (Beta)](https://hyperbrowser.ai/docs/sandboxes/macos.md) for full workflows.


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