Skip to main content
Use --json and parse stdout when automating the Box CLI. For typed HTTP clients, use the Python SDK or TypeScript/JavaScript SDK. Some commands emit one JSON object. Long-running commands emit JSON Lines: one JSON object per line. Argument parsing errors can still be emitted by the CLI parser on stderr before Box’s JSON error handler runs. For non-interactive environments, create a Box API key with box api-key create and pass it as BOX_API_KEY; see API Keys for setup. For runtime secrets inside Boxes, use Dashboard > Secrets. Dashboard secrets are injected as environment variables and secret files; configure them before running setup scripts or prompts that need credentials. See Secrets & Setup for the dashboard workflow and setup-script guidance.
Treat desktopUrl and viewerUrl as secrets. They can include short-lived desktop access tokens.

Authenticate

Authenticate once before the first command in a process or container:
Output:
To provision the key itself per project, from a session that signed in through the browser flow (API-key auth cannot mint keys):
The secret is only ever present in this one response; box api-key list --json returns metadata without secrets. If you run box login --json without a key, the CLI starts the browser flow instead:

Output contract

Commands that return a single JSON object: Commands that emit JSONL:

Setup Scripts and Secrets

The usual setup flow is:
  1. Configure secrets in Dashboard > Secrets.
  2. Create a Box with box new --json and wait for the ready event.
  3. Run a non-interactive command with box ssh.
Secrets configured in the dashboard are available as process environment variables and configured secret files inside the Box. Prefer this over passing secret values in prompts, URLs, or command arguments. box ssh <id> <command> prepares and registers the CLI-managed SSH key, then runs the command without opening an interactive shell. It streams stdin, stdout, and stderr, so a setup script can run without copying it into the Box first.
On Windows PowerShell:
PowerShell’s native pipeline can keep stdin open for native executables in some environments. For Windows automation, run setup through Node, Python, WSL, Git Bash, or cmd.exe. If you need the Box to keep running for a long uninterrupted workflow, disable auto-stop when creating it:
See Long-Running Tasks. Do not rely on runtime processes surviving resume or fork. After box resume or box fork, check app servers, workers, dev servers, tunnels, and desktop sessions, and run your setup or start command again if needed.

Errors

Most failed CLI commands in --json mode emit one final JSON line to stdout and exit non-zero. Commands that normally emit one JSON object still use this JSONL error line on runtime failure. Argument parsing failures, such as missing required flags or invalid numeric flag values, are emitted by the CLI parser on stderr and may not be JSON.
Backend API failures include code and status. The backend field is named error; the CLI exposes that backend code as code so error can stay human-readable.
Local CLI failures do not include code or status because no Box API error response was received:
Network failures also use the local shape:
Type:
The backend error object for Box CLI API paths is one of these shapes:
The CLI uses message when present. If there is no message, it humanizes known backend codes such as unauthorized, not_found, account_not_ready, method_not_allowed, and rate_limited; otherwise it formats the backend code and HTTP status.
Treat CLI error output as sensitive. For backend errors that include billingUrl, setupUrl, or dashboardUrl, the CLI may append a dashboard URL with box_token to the human-readable error string.
Common backend codes used by the Box CLI paths: Local CLI validation can fail before the backend is called. These errors have no stable code today. Examples from the current CLI source include invalid provider, invalid model, invalid reasoning effort, empty API key, missing local login, unsupported HTTP method, invalid local JSON from the API, SSH/SCP exit failures, and unreachable API host.

Common types

Box

The CLI presents backend states for users: provisioned becomes ready, archiving becomes stopping, and archived becomes stopped.

BoxListResult

box list --json defaults to up/running boxes, the same as box list --filter r --json. Use box list --filter s --json for stopped boxes, combine groups like --filter sr, or use --all --json to include every state. Example:

BoxInfoResult

BoxActionResult

Used by stop, resume, fork, and interrupt.

DesktopResult

HostResult

VncDesktopResult

ApiKeySecretResult

Returned by box api-key create --json and box api-key rotate --json. The secret exists only in this response and can never be retrieved again.

ApiKeyListResult

box api-key list --json returns keys you created; add --all to include platform-managed per-box machine keys (sandboxId set).

ConfigResult

LimitsResult

Create a box

box new --json emits JSONL, not a single JSON object.
Schema:

Prompt and events

box prompt --provider codex <id> "..." --json first emits a queued line:
Then it emits chat lines until the prompt finishes. box events --json emits the same chat line shape for persisted events. It may return fewer lines than box prompt --json; in a live check, box prompt emitted queued, queued-prompt, running-prompt, finished-prompt, and response lines, while box events later returned the persisted finished-prompt and response lines.
Schema:
response chat events can include tool data in data.tools; keep the full object if you need exact agent traces.

Bash JSONL parser

Node.js

Use a single-object helper for commands like info, and a JSONL helper for commands like new.

Python

Direct SSH

The CLI manages the SSH key. For an interactive shell, prefer:
For box scp, remote paths are passed through to OpenSSH scp after the <box-id>: prefix. Absolute paths such as /home/user/setup.sh are the safest. Relative remote paths are resolved from the SSH user’s home directory (/home/user on hosted Boxes). Avoid relying on ~ in automation because expansion can vary by local shell and scp mode. For non-interactive commands, pass the command after the box ID:
For direct SSH, inspect the Box for its IP and use the CLI-managed key: