# CLI reference

> Every sbx command and flag, with JSON output for scripts.

`sbx` is one static binary for Linux, macOS and Windows. Most commands map to an API call, and `--json` gives machine-readable output for scripts.

```bash
curl -fsSL https://sandboxer.com/install | sh      # macOS / Linux
irm https://sandboxer.com/install.ps1 | iex        # Windows PowerShell
sbx update                                          # update in place (also: sbx self-update)
```

When you run an out-of-date `sbx`, the command still works and ends with one line saying so, for example "sbx 5750b620 is out of date; run `sbx update` (9eff74cd)". `--no-update` or `SANDBOXER_NO_UPDATE=1` turns the line off. If a release is ever known to be broken, the API refuses it with `426 client_outdated` and says how to upgrade.

## Global flags

| Flag | Env | Meaning |
| - | - | - |
| `--api-url <url>` | `SANDBOXER_API_URL` | Use another API endpoint |
| `--org <id or name>` | `SANDBOXER_ORG` | Bill this one command to an organization (or `personal`) |
| `--json` | | Machine-readable output. Turns on automatically when stdout is not a terminal |
| `--no-update` | | Skip the update check |

### Sandbox aliases

Anywhere a sandbox id is expected you can write:

| Alias | Means |
| - | - |
| `current` | The last sandbox created in this shell (or the one you omitted the id for) |
| `self` | The sandbox the CLI is running inside |

## Scripts and CI

```bash
sbx login --key-stdin --json <<< "$SANDBOXER_API_KEY"
id="$(sbx new --type small --json | jq -r 'select(.event=="ready") | .id')"
sbx exec "$id" "npm ci && npm test"
sbx stop "$id" --json
```

Most commands print one JSON object. `new`, `prompt`, `events` and `conversations` print JSON Lines — parse line by line. On failure in `--json` mode the last line is `{"event":"error","error":"…","code":"…","status":…}` and the exit code is non-zero.

| Exit code | Meaning |
| - | - |
| `0` | Success |
| `1` | Any other error (the API's `code` is in the error line) |
| `2` | Usage error: a wrong flag or argument |
| `3` | Not signed in, or the key was refused (HTTP 401) |
| `4` | Not found (HTTP 404) |
| `5` | Timed out waiting |

`sbx exec` and `sbx ssh` exit with the remote command's own exit code instead.

In a container, download the binary directly:

```dockerfile
RUN curl -fsSL "https://sandboxer.com/dl/sbx-linux-$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')" -o /usr/local/bin/sbx \
 && chmod +x /usr/local/bin/sbx
```

### Shell completion

```bash
eval "$(sbx completion bash)"      # ~/.bashrc
eval "$(sbx completion zsh)"       # ~/.zshrc, after compinit
sbx completion fish > ~/.config/fish/completions/sbx.fish
sbx completion powershell | Out-String | Invoke-Expression
```

Completion includes subcommands and the ids of your live sandboxes.

## Account and sign-in

### sbx onboard

Sets up this computer: browser sign-in (GitHub, Google, an email code, or email and password), saves the token, and asks only what your account still needs. Safe to re-run.

```bash
sbx onboard                              # asks: GitHub, Google, or email
sbx onboard --google
sbx onboard --email you@example.com
```

### sbx login

```bash
sbx login                                # browser sign-in; asks: GitHub, Google, or email
sbx login --github                       # or --google: go straight to that provider
sbx login --email you@example.com
sbx login --key-stdin <<< "$SANDBOXER_API_KEY"
sbx login sbx_live_…                     # key as an argument (visible to other users' ps)
```

Browser sign-in prints a short code and opens `/device`, where you approve it. The CLI waits up to six minutes.

### sbx logout / sbx status

```bash
sbx logout      # forget the local token
sbx status      # API health, signed-in account, plan, config path
```

### sbx api-key

```bash
sbx api-key create my-service --ttl 90d --preset ci
sbx api-key create reader --preset read-only
sbx api-key create one-box --ttl 7d --sandbox sb_k3v9x2mq --actions sandbox.read,exec
sbx api-key list [--all]
sbx api-key usage <id> [--verbose]
sbx api-key rotate <id>
sbx api-key revoke <id>
```

| Flag | Rule |
| - | - |
| `--ttl` | Default `90d`, maximum `365d` |
| `--preset` | `read-only`, `full-sandbox`, `ci`, `admin` |
| `--actions` | Comma-separated; not with `--preset` |
| `--sandbox`, `--env` | Repeatable; restrict the key to these sandboxes / environments |

`create` and `rotate` print the secret once. See [API keys](/docs/api-keys).

### sbx webhook

```bash
sbx webhook create https://example.com/hooks/sbx --name prod --event ready --event error
sbx webhook list
sbx webhook rotate <id>
sbx webhook remove <id>
```

`--event` takes `ready`, `error`, `archived`, `hydrated`, `degraded`, `recovered` (the `sandbox.` prefix is optional); omit it for all events. See [Webhooks](/docs/webhooks).

### sbx telemetry

```bash
sbx telemetry
sbx telemetry set https://otlp.example.com -H api-key=$KEY
sbx telemetry unset
```

## Lifecycle

### sbx new

```bash
sbx new
sbx new --type large --ttl 28800
sbx new --no-auto-stop
sbx new -e KEY=value -e OTHER=value
sbx new --environment staging
sbx new --no-env
sbx new --from web-stack
sbx new --from bsh_…
sbx new --setup-file ./setup.sh
sbx new --region us-east
sbx new --fail-fast
sbx new --no-snapshots
sbx new --no-monitoring
sbx new --personal
sbx new --idle 60
sbx new --name "api server"
sbx new --no-wait
```

| Flag | Default | Notes |
| - | - | - |
| `--type` | `default` | `small`, `default`, `large`, `xlarge` |
| `--region` | nearest to you | `us-east` or `eu-central` ([Regions](/docs/regions)) |
| `--ttl <seconds>` | `3600` | Up to `2592000` (30 days) |
| `--no-auto-stop` | off | Never stop automatically |
| `--name <name>` | | Display name |
| `--no-wait` | off | Return as soon as the sandbox is accepted, without waiting for `ready` |
| `--idle <minutes>` | your plan's | Pause (stop with memory) after this many idle minutes, waking on use; `0` never, up to `10080` |
| `-e`, `--env KEY=VALUE` | | Per-sandbox variable; repeatable |
| `--environment <name>` | your default | Which environment to start from |
| `--no-env` | off | None of your secrets or credentials |
| `--from <name or code>` | | Start from a named snapshot or a share code |
| `--setup-file <path>` | | Script run in the background after ready (≤ 64 KB) |
| `--fail-fast` | off | Fail in ~1.5 s with `no_ready_machine` instead of waiting |
| `--no-snapshots` | off | Never snapshot; stopping erases the sandbox |
| `--no-monitoring` | off | Keep no command output, process list or metrics |
| `--personal` | off | Bill yourself even if an org wallet is active |

Prints the id, subdomain, IPs and states as it goes; returns when the sandbox is `ready`.

### sbx list

```bash
sbx list                 # running sandboxes (same as --filter r)
sbx list --filter s      # stopped
sbx list --filter sr     # stopped and running
sbx list --all
```

Filter letters: `r` running (`ready`, `idle`, `running`, `cloning`), `s` stopped, `p` pending (`init`, `provisioning`), `t` stopping, `e` error.

### sbx regions

```bash
sbx regions
```

Lists the regions and marks your nearest region, which is where new sandboxes go by default. `--json` prints the `GET /api/v1/regions` response. A fork, or a sandbox made from a snapshot, stays in its source's region; there is no `--region` on `sbx fork`. See [Regions](/docs/regions).

### sbx rename

```bash
sbx rename sb_k3v9x2mq --name "api server"
sbx rename sb_k3v9x2mq --subdomain blue-owl-api
```

A new subdomain re-points every hosted URL and the SSH endpoint at once; the old one stops working.

### sbx info

```bash
sbx info sb_k3v9x2mq
```

State, size, IPs, subdomain, auto-stop deadline, last snapshot, setup status, environment version.

### sbx extend

```bash
sbx extend sb_k3v9x2mq --hours 12
sbx extend sb_k3v9x2mq --ttl 86400
sbx extend sb_k3v9x2mq --no-auto-stop
```

### sbx idle

```bash
sbx idle sb_k3v9x2mq 60      # pause after 60 idle minutes
sbx idle sb_k3v9x2mq 0       # never pause
```

Sets `idleStopMinutes`; see [idle auto-pause](/docs/long-running#idle-auto-pause-and-wake-on-use).

### sbx stop

```bash
sbx stop sb_k3v9x2mq
sbx stop sb_k3v9x2mq --status stop_3f9a1c2e7b4d5a60
sbx stop sb_k3v9x2mq --force
```

Snapshots memory and disk and stops billing. `--status` reads a stop operation. `--force` discards anything written since the last good snapshot — only for stops that were refused.

### sbx resume

```bash
sbx resume sb_k3v9x2mq
sbx resume sb_k3v9x2mq --type large --ttl 7200
sbx resume sb_k3v9x2mq -e KEY=value          # replaces per-sandbox variables
sbx resume sb_k3v9x2mq --environment prod
sbx resume sb_k3v9x2mq --no-env              # one-way
sbx resume sb_k3v9x2mq --no-auto-stop
sbx resume sb_k3v9x2mq --fail-fast
sbx resume sb_k3v9x2mq --require-memory     # wait (up to 30 min) for memory; never boot from disk
```

Restores memory, so running processes come back. Waits until a test command succeeds before printing `ready`. A size change cold-boots from disk.

### sbx fork

```bash
sbx fork sb_k3v9x2mq
sbx fork sb_k3v9x2mq --type large --ttl 600 -e TENANT=acme
sbx fork sb_k3v9x2mq --environment demo --no-env
sbx fork sb_k3v9x2mq --name "try-fix-2"
```

Creates an independent copy of the sandbox's disk as it is now (not its memory or processes). Default TTL is one hour, whatever the source had. `--name` sets the copy's display name.

### sbx recover

```bash
sbx recover sb_k3v9x2mq
```

Power-cycles an unresponsive machine without touching its disk. Refused if the sandbox answers normally or was recovered in the last 10 minutes.

### sbx delete / sbx deletion status

```bash
sbx delete sb_k3v9x2mq
sbx delete sb_k3v9x2mq --yes
sbx deletion status bdop_0123456789abcdef0123456789abcdef
```

Permanently deletes the sandbox and the snapshots only it uses. Asks for confirmation unless `--yes` (required in scripts). If you might need the data, `stop` instead — stopped sandboxes are free.

### sbx share

```bash
sbx share sb_k3v9x2mq
```

Gives an organization sandbox to the whole team; your personal logins are wiped at its next start.

## Access

### sbx ssh

```bash
sbx ssh sb_k3v9x2mq
sbx ssh sb_k3v9x2mq "cd app && npm test"
sbx ssh sb_k3v9x2mq -- bash -lc 'echo $HOME'
sbx ssh sb_k3v9x2mq -- bash -s < ./setup.sh
```

Tunnels over HTTPS; manages `~/.ssh/sandboxer_ed25519`. See [SSH](/docs/ssh).

### sbx exec

```bash
sbx exec sb_k3v9x2mq "npm test"
sbx exec sb_k3v9x2mq --cwd app --timeout 120 -- npm run build
sbx exec sb_k3v9x2mq --detach "npm run build"
sbx exec sb_k3v9x2mq --status 4120
sbx exec sb_k3v9x2mq --attach 4120
sbx exec sb_k3v9x2mq --stream "npm run build"
sbx exec -it sb_k3v9x2mq bash
sbx exec sb_k3v9x2mq --kill 4120
```

| Flag | Default | Meaning |
| - | - | - |
| `--cwd <dir>` | `/home/user` | Relative to the home directory |
| `--timeout <secs>` | `30` | 1–600 for synchronous runs |
| `--detach` | | Run in background, print `processId` |
| `--status <pid>` | | Status and tail of a detached process |
| `--attach <pid>` | | Follow its output until it exits; exits with its code |
| `--kill <pid>` | | Stop it and its children |
| `--stream` | | Print output as the command writes it |
| `-i`, `--interactive` | | Keep stdin open (over a WebSocket) |
| `-t`, `--tty` | | Allocate a terminal (over a WebSocket) |
| `-e KEY=VALUE` | | Environment variable for `-i`/`-t`; repeatable |

One argument runs as a shell command line; several run as argv. Exits with the remote exit code.

A synchronous run stops after `--timeout` (30 s by default), so give installs and builds more: `sbx exec <id> --timeout 600 "apt-get install -y …"`, or run them with `--detach` and follow them with `--attach`. A run that times out is killed and `sbx exec` exits `124` (as `timeout(1)` does); `sbx history` lists it as `timed out (exit 124)`, and the API's `exitCode` for it is the killed process's `137`.

### sbx history / sbx ps

```bash
sbx history sb_k3v9x2mq [--limit 50] [--mode commands] [--grep npm]
sbx history sb_k3v9x2mq cmd_k3v9x2mq7tbw [--stderr] [--follow]
sbx ps sb_k3v9x2mq
```

### sbx env

```bash
sbx env list
sbx env info base
sbx env new staging
sbx env rename staging prod
sbx env default prod
sbx env rm staging
sbx env set base --safe-for-third-parties false --github true --secrets true --sandbox-credentials true --agents-credentials true
sbx env set-var base KEY=value
sbx env rm-var base KEY
sbx env set-file base path/in/home --from ./local-file
sbx env rm-file base path/in/home
sbx env add-repo base acme/web --branch main
sbx env rm-repo base acme/web
sbx env upgrade base
```

See [Environments](/docs/environments).

### sbx host

```bash
sbx host sb_k3v9x2mq 3000
sbx host sb_k3v9x2mq 3000 --title "Preview" --public
sbx host sb_k3v9x2mq 5173 --localhost
sbx host list sb_k3v9x2mq
sbx host hide sb_k3v9x2mq 3000
```

| Flag | Meaning |
| - | - |
| `--title` | Label shown on the dashboard |
| `--private` (default) | URL requires its `_token` |
| `--public` | No token needed |
| `--localhost` | The app listens on 127.0.0.1 / ::1 only |

Inside a sandbox, the pre-installed `host 3000` does the same for the current sandbox.

### sbx ssh-config

```bash
sbx ssh-config             # print a Host *.sbx stanza for ~/.ssh/config
sbx ssh-config --install   # append it to ~/.ssh/config (once)
```

With it, `ssh sb_k3v9x2mq.sbx`, `rsync` and VS Code Remote-SSH reach a sandbox through the CLI tunnel (`ProxyCommand sbx proxy %h`).

### sbx scp

```bash
sbx scp ./file sb_k3v9x2mq:/home/user/
sbx scp sb_k3v9x2mq:/home/user/out.zip .
sbx scp -r ./dir sb_k3v9x2mq:/home/user/
```

### sbx forward

```bash
sbx forward sb_k3v9x2mq --remote 5432 [--local 15432] [--bind 127.0.0.1]
sbx forward sb_k3v9x2mq --reverse --local 11434 [--remote 11500]
```

### sbx desktop / sbx browser

```bash
sbx desktop sb_k3v9x2mq [--vnc] [--public]
sbx browser sb_k3v9x2mq [--profile /data/chrome-profile]
```

## Snapshots

```bash
sbx snapshots [sb_k3v9x2mq]                     # list
sbx snapshot sb_k3v9x2mq web-stack              # save a named snapshot
sbx snapshot save sb_k3v9x2mq web-stack [--no-wait]   # the same
sbx snapshot info web-stack                     # one named snapshot
sbx snapshot rm web-stack                       # remove it
sbx snapshot share web-stack                    # make a bsh_… code (shown once)
sbx snapshot shares web-stack
sbx snapshot unshare web-stack shr_1a2b3c
sbx snapshot latest sb_k3v9x2mq
sbx snapshot tree <snapshotId>
sbx snapshot pull <snapshotId> -o ./restore
sbx snapshot delete <snapshotId>... [--yes]
sbx snapshot delete --all sb_k3v9x2mq
```

## Agents

### sbx prompt

```bash
sbx prompt "Fix the failing tests"
sbx prompt sb_k3v9x2mq --provider codex --model gpt-5.4 --reasoning-effort high "Refactor auth"
sbx prompt --fast "Summarize the diff"
sbx prompt --new "Start a second task"
sbx prompt --resume <conversationId> "Continue"
sbx prompt --attach ./error.png --attach ./trace.log "Why does this crash?"
```

| Flag | Values |
| - | - |
| `--provider` | `claude`, `codex`, `opencode`, `pi`, `prime`, `kimi`, `mistral` |
| `--model` | From `sbx prompt --help` (live catalog) |
| `--reasoning-effort` | `none`, `low`, `medium`, `high`, `xhigh`, `max` — per model |
| `--fast` | Fast mode on supported models |
| `--new`, `--resume <id>` | Start or continue a conversation |
| `--attach <path>` | Repeatable; saved under `~/attachments` |

### sbx events / conversations / steer / interrupt

```bash
sbx events sb_k3v9x2mq [--follow] [--convo <id>|current]
sbx conversations sb_k3v9x2mq                     # alias: sbx convos
sbx steer sb_k3v9x2mq [--convo <id>] "Also update the changelog"
sbx interrupt sb_k3v9x2mq [--convo <id>]
```

### sbx handoff

```bash
sbx handoff                                                    # in the repo where the agent works
sbx handoff --agent codex --prompt "Finish the migration, then run the tests"
sbx handoff --back                                             # bring the work and the session home
```

Moves a local Claude Code or Codex session and its repo into a sandbox and resumes the agent there, headless, so you can close your laptop. It saves every change, untracked files too, on a temporary branch without touching yours. It pushes that branch into the sandbox over SSH, never to a remote, then moves the session file. It shows what will move and asks first unless you pass `--yes`.

- **API key only:** the agent runs with the Anthropic or OpenAI API key saved on your [Agents page](/app/agents), never a subscription login. Without a key, nothing moves.
- **`.env` files stay behind** unless you pass `--include-env`.
- **`--back`** brings the work back as uncommitted changes on your branch, and the session back for `claude --resume` or `codex resume`. If your repo changed since the handoff, nothing is applied: the sandbox's work is fetched to a branch and the merge command is printed. The sandbox keeps running, so `sbx stop` it when you're done.
- **One handoff per repo** at a time, and the repo needs at least one commit.

| Flag | Meaning |
| - | - |
| `--agent` | `claude` or `codex` (default: the most recent session in this repo) |
| `--session` | The session to hand off: its id or transcript path |
| `--sandbox <id>` | Use this running sandbox instead of creating one |
| `--prompt <text>` | What the agent does next (default: continue where it left off) |
| `--model <m>` | Model for the resumed agent |
| `--type <size>` | Size of a new sandbox: `small`, `default`, `large` or `xlarge` |
| `--include-env` | Also copy `.env` files (they may hold secrets) |
| `-y`, `--yes` | Don't ask first (needed with `--json` or without a terminal) |
| `--back` | Bring the sandbox's work and the session back to this repo |
| `--force` | With `--back`: even while the agent is still working |

Agents can do the same with the `handoff_session` tool in the local [`sbx mcp`](/docs/mcp) server.

### sbx mcp

```bash
sbx mcp                          # MCP server on stdin/stdout
sbx mcp --type small --ttl 1800  # defaults for the sandboxes the agent creates
claude mcp add sandboxer -- sbx mcp
```

Runs a [Model Context Protocol](/docs/mcp) server with the tools `create_sandbox`, `list_sandboxes`, `exec`, `read_file`, `write_file`, `host_port`, `stop_sandbox` and `resume_sandbox`. It signs in like every other command (`sbx login` or `SANDBOXER_API_KEY`).

| Flag | Default | Meaning |
| - | - | - |
| `--type` | `default` | Size of sandboxes created without a `type` |
| `--ttl <seconds>` | `3600` | Auto-stop for sandboxes created without `ttlSeconds`; `0` never stops |

## Account

```bash
sbx limits [--json]                       # starts left, hours left, pack balance
sbx usage sb_k3v9x2mq [--since 2026-09-01 --until 2026-10-01]
sbx dashboard                             # open the dashboard, already signed in
sbx org                                   # active wallet
sbx org list
sbx org switch acme | personal
sbx org create "Acme"
sbx org members
sbx org invite dana@example.com
sbx --org acme org transfer dana
sbx --org acme org delete --yes
sbx billing                               # plan, renewal, balance, auto-refill
sbx billing plan [100]
sbx billing credits 3                     # buy three time packs
sbx billing autorefill on|off
sbx billing portal
sbx data-retention status
sbx data-retention enable [--yes]
sbx self-update
```

Configuration lives at `~/.config/sandboxer/config.json`; `sbx status` prints the path.
