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

# Sandbox CLI

> Use the Hyperbrowser CLI to create and manage sandboxes

The `hx` CLI covers the sandbox workflows in this section: profile setup, sandbox creation, volume management, process execution, file transfer, terminals, snapshots, image builds, and port exposure.

Use the CLI when you want a shell-first workflow or need to script sandbox operations outside the SDKs. For the underlying API concepts, see [Creating Sandboxes](/sandboxes/create), [Volumes](/sandboxes/volumes), [Sandbox Lifecycle](/sandboxes/lifecycle), [Sandbox Processes](/sandboxes/processes), [Local Filesystem](/sandboxes/filesystem/overview), [Base Images](/sandboxes/base-images), [Build And Upload A Custom Image](/sandboxes/custom-images), and [Sandbox Terminal](/sandboxes/terminal).

## Install

See [Install](/sandboxes/install) for macOS, Linux, Windows, and direct-download instructions.

## Configure Profiles

Login with your account

```bash theme={null}
hx auth login
```

Login with and save credentials to a profile:

```bash theme={null}
hx auth login --profile dev
```

List saved profiles and run a command with a specific profile:

```bash theme={null}
hx profile list
hx --profile dev vm list
```

<Tip>
  The CLI uses the `default` profile unless you pass `--profile`. `hx configure`
  prompts for an API key if `--api-key` is omitted and stores profiles in
  `~/.hx_config/config`.
</Tip>

## Open The Dashboard

Launch the interactive dashboard:

```bash theme={null}
hx dash
```

<Note>
  `hx dash` requires an interactive terminal. Running `hx` without a subcommand
  shows help; it does not open the dashboard automatically.
</Note>

## Manage Volumes

Create, list, and inspect persistent volumes:

```bash theme={null}
hx vm volumes create my-workspace
hx vm volumes ls
hx vm volumes get <volume-id>
```

Attach a volume at sandbox launch:

```bash theme={null}
hx vm create node --mount <volume-id>:/mnt/workspace
hx vm create node --mount <volume-id>:/mnt/cache:ro
hx vm create node --mount source=<volume-id>,target=/mnt/workspace
hx vm create node --mount source=<volume-id>,target=/mnt/cache,readonly
```

<Note>
  See [Managing Volumes](/sandboxes/volumes/managing) and
  [Mounting Volumes](/sandboxes/volumes/mounting) for API-level rules.
</Note>

## Create Sandboxes

Launch from an image:

```bash theme={null}
hx vm create node
hx vm create node --port 3000 --port 9222:auth
hx vm create image:node
hx vm create --image-name node --region us --timeout-minutes 30
hx vm create --image-name node --image-id <image-id> --port 3000 --auth
hx vm create --image-name node --image-id <image-id> --enable-recording
```

Launch from a snapshot:

```bash theme={null}
hx vm create my_snapshot --snapshot
hx vm create snapshot:my_snapshot --snapshot-id <snapshot-id>
hx vm create --snapshot-name my_snapshot --snapshot-id <snapshot-id>
```

## Build And List Images

<Note>
  `hx vm image build` packages a local Docker image before uploading it, so image
  builds require Docker to be available locally.
</Note>

Build a Firecracker image from a local Docker image:

```bash theme={null}
hx vm image build node:22 custom_node
hx vm image build myorg/app:latest app_prod --env NODE_ENV=production --env PORT=3000
hx vm image build myorg/app:latest app_prod --entrypoint 'npm run start'
```

List available images:

```bash theme={null}
hx vm image list
hx --json vm image list
```

<Tip>
  `hx vm image build` also supports `--wait-timeout` and `--poll-interval` when
  you want to control how long the CLI waits and how often it polls build
  status.
</Tip>

## Inspect, Stop, And Expose Sandboxes

List and inspect sandboxes:

```bash theme={null}
hx vm list
hx vm list --status closed --page 1 --limit 20
hx vm get <sandbox-id>
hx --json vm get <sandbox-id>
```

Stop a sandbox:

```bash theme={null}
hx vm stop <sandbox-id>
```

Expose or remove an exposed sandbox port:

```bash theme={null}
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
```

<Tip>
  `hx vm expose` currently accepts exactly one `--port` value. Use
  `<port>:auth` or `<port>:public` when you want to override the default auth
  mode from `--auth`.
</Tip>

<Tip>
  Sandbox workflows are grouped under the `hx vm` namespace (for example
  `hx vm create`, `hx vm process`, `hx vm connect`, and `hx vm volumes`).
</Tip>

## Run Commands

Run a one-shot command inside a sandbox:

```bash theme={null}
hx vm exec <sandbox-id> 'pwd'
hx vm exec <sandbox-id> 'echo hello'
hx vm exec --cwd /tmp --env FOO=bar <sandbox-id> 'echo $FOO'
```

## Manage Long-Running Processes

Start a background process:

```bash theme={null}
hx vm process start <sandbox-id> 'python3 -m http.server 3000'
hx --json vm process start <sandbox-id> 'sleep 30'
```

Inspect, wait for, and stream a process:

```bash theme={null}
hx vm process get <sandbox-id> <process-id>
hx vm process list <sandbox-id>
hx vm process list <sandbox-id> --status running --limit 20
hx vm process wait <sandbox-id> <process-id>
hx vm process stream <sandbox-id> <process-id>
hx vm process stream <sandbox-id> <process-id> --from-seq 120
```

Send input or terminate a process:

```bash theme={null}
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>
```

## Work With Files

Copy files and directories between your machine and a sandbox:

```bash theme={null}
hx vm cp ./local.txt <sandbox-id>:/tmp/local.txt
hx vm cp <sandbox-id>:/tmp/local.txt ./downloaded.txt
hx vm cp ./dir/. <sandbox-id>:/tmp/dir-contents
hx vm cp <sandbox-id>:/tmp/a.txt <sandbox-id>:/tmp/b.txt
```

Read a file directly from a sandbox:

```bash theme={null}
hx vm read <sandbox-id> /tmp/file.txt
hx vm read --encoding raw <sandbox-id> /tmp/file.bin
hx vm read --encoding base64 <sandbox-id> /tmp/file.bin
hx vm read --offset 0 --length 128 <sandbox-id> /tmp/file.txt
```

<Warning>
  The `<sandbox-id>:/path` shorthand is only supported by `hx vm cp`.
  `hx vm read` expects the sandbox ID and path as separate arguments.
</Warning>

## Open An Interactive Terminal

Open a terminal in a selected sandbox:

```bash theme={null}
hx vm connect
```

Open a terminal in a specific sandbox:

```bash theme={null}
hx vm connect <sandbox-id>
```

Override the default command or set a working directory:

```bash theme={null}
hx vm connect <sandbox-id> --command python3 --arg -i
hx vm connect <sandbox-id> --cwd /tmp
hx vm connect <sandbox-id> --env FOO=bar
```

<Tip>
  By default, `hx vm connect` starts `/bin/bash -i -l`.
</Tip>

## Create And Restore Snapshots

Create a memory snapshot from a running sandbox:

```bash theme={null}
hx vm snapshot create <sandbox-id> my_snapshot
```

List snapshots:

```bash theme={null}
hx vm snapshot list
hx vm snapshot list --limit 20
```

Restore from a snapshot:

```bash theme={null}
hx vm create my_snapshot --snapshot
hx vm create --snapshot-name my_snapshot --snapshot-id <snapshot-id>
```

## JSON Output

Most commands support `--json` for scripting:

```bash theme={null}
hx --json vm create node --port 3000:auth
hx --json vm get <sandbox-id>
hx --json vm expose <sandbox-id> --port 3000:public --auth
hx --json vm process start <sandbox-id> 'echo hi'
hx --json vm cp ./file.txt <sandbox-id>:/tmp/file.txt
```
