--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.
Authenticate
Authenticate once before the first command in a process or container: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:- Configure secrets in Dashboard > Secrets.
- Create a Box with
box new --jsonand wait for thereadyevent. - Run a non-interactive command with
box ssh.
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.
cmd.exe.
If you need the Box to keep running for a long uninterrupted workflow, disable auto-stop when creating it:
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.
code and status. The backend field is named error; the CLI exposes that backend code as code so error can stay human-readable.
code or status because no Box API error response was received:
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.
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
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 bystop, resume, fork, and interrupt.
DesktopResult
HostResult
VncDesktopResult
ApiKeySecretResult
Returned bybox 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.
Prompt and events
box prompt --provider codex <id> "..." --json first emits a queued line:
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.
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 likeinfo, and a JSONL helper for commands like new.
Python
Direct SSH
The CLI manages the SSH key. For an interactive shell, prefer: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: