Skip to content

Headless runs

Run abx from scripts and CI without a terminal, with JSON results, stable exit codes and a one-line error envelope.

Updated

Use this page when a script, a CI job or another program runs abx and no person is at the terminal. It covers the flags that make a launch one-shot, how to read the exit status, and where results and errors go. To drive abx from another coding agent, read Driving abx from a coding agent as well.

The headless form

abx claude fix-auth --no-create --no-tty -- -p "fix the failing test"
abx shell fix-auth --no-create -- npm test

Everything after -- goes to the guest verbatim. abx waits for the command and exits with its status.

Flag Effect
--no-tty Run without a pseudo-terminal, as a one-shot command.
--no-create Fail with no-box instead of creating a box when the named box (or any box, when none is named) does not exist. It is the default when ABX_JSON=1 is set.
--create Create a missing box even when ABX_JSON=1 is set. Giving both --create and --no-create is a usage error.
--json Print the result as JSON on stdout and report failures as an error envelope. Accepted by commands whose reference entry lists a JSON shape.

A launch is also one-shot when it has a guest command after -- for shell, or when stdin or stdout is not a terminal. An agent launch with arguments after -- still attaches a terminal when one exists, so pass --no-tty in scripts.

Boxes belong to a Git checkout or to the exact scratch directory. Run from the checkout, or pass -C DIR.

Exit codes

Code Meaning
0 Success.
1 The command failed.
2 Usage error.
125 In a one-shot run or shell, abx itself failed, with any error code including a usage error. On Linux, host policy also exits 125 when it refuses a command, for example when running as root.
128+n A one-shot command was killed by signal n, for example 143 for SIGTERM.

In a one-shot launch, only 125 means abx failed. Any other status is the guest command’s, so 1 or 2 can come from the agent or from your tests rather than from abx. Check for 125 first, then read the error envelope on stderr. For the other commands, 1 and 2 are abx’s own. See Exit codes for the full list.

SIGTERM and SIGHUP sent to abx are forwarded to the guest command, and so are SIGINT and SIGQUIT sent with kill.

Streams

Results and JSON go to stdout. Progress, notices and errors go to stderr, and an error line starts with abx: when stderr is not a terminal. Without a terminal, plain ls prints tab-separated columns (followed by any access entries at the end) and plain net prints the mode followed by space-separated allowed hosts on one line, but prefer --json.

The error envelope

When --json is among the arguments before --, or ABX_JSON=1 is set, a failure leaves stdout empty and the last line of stderr is a single-line JSON object:

{"error":{"code":"no-box","message":"No managed box has that name in this scratch directory.","hint":null,"retryable":false}}
  • Branch on code. It is stable; message and hint are not.
  • hint is the command or step that resolves the failure, or null.
  • retryable is true when running the same command again may succeed. Only lock-busy is retryable. Locks never wait, so retry after a short pause.
  • Notices and progress can come before the envelope, so read the last line of stderr.

This holds for usage errors too, so abx bogus --json also produces an envelope. A command that acts on several boxes (abx rm a b, abx stop --all) can instead exit 1 with a result on stdout and the failures in failed[], each with its own error object and no envelope.

For the output shapes see JSON output, and for every code with its meaning and fix see Error codes.

Commands that need a terminal

abx tui, abx wizard and abx auth login always need a terminal and fail with needs-terminal without one. abx shell without a terminal needs a command after --, or it fails with needs-terminal. For modes that store a secret (such as Claude’s default oauth-token or an API key), abx auth set prompts on the terminal unless you pass --from <secret reference>; without a terminal that prompt fails with Keyring setup requires a terminal. Supply --from to save a provider reference. and the code internal. abx help --json describes each command’s requirement in its terminal field.

Environment

Variable Use in scripts
ABX_JSON=1 Report failures as the JSON envelope without --json, and make launches fail instead of creating a box. Results on stdout are unchanged.
ABX_HOME Absolute directory for host state, default ~/.abx.
NO_COLOR Disable colors on terminals.

There is no detached start. A one-shot launch runs in the foreground until the command ends, so run it as a background job of your own if you need to do something meanwhile.

Type to search…

↑↓ navigate↵ selectEsc close