Skip to content

Driving abx from a coding agent

The order of operations for a coding agent that runs abx on your behalf, from discovery and readiness checks to review and landing.

Updated

Use this page when one coding agent (or any program) runs abx to start work in boxes. It says which commands to call and in what order. The flags and exit codes are covered in Headless runs.

Discover

abx help --json prints the whole command reference: usage lines, options, notes, the shape of each command’s --json output, the error codes and the environment variables. Read it once per session. It has a schemaVersion, currently 5. abx help <command> prints the same for one command as text.

Three fields tell a caller what a command does to the machine:

  • terminal is never, always or unless <condition>. Do not call a command whose value is always (abx tui, abx wizard, abx auth login) without a terminal. It fails with needs-terminal.
  • startsBox: true marks commands that can start the box’s VM: launches, diff, land and rm. They can take several seconds and can fail on the box’s state.
  • bootsProbeMachine: true marks abx auth verify, which also makes a real model request and can incur provider charges.

Check readiness

abx status --json

abx status starts no VM, never creates $ABX_HOME and never writes a workspace marker. Check backend.supported, image.present and, for the agent you want, agents[].ready (the agent is in the image and has a saved sign-in; a masked credential is released only after abx auth verify, and the configured mode in agents[].auth.modes then has status: "verified"). next lists the steps to run in order. Each has a complete argv with no placeholders, a reason and needsTerminal.

  • An entry with needsTerminal: true needs a person, for example abx auth set claude, which prompts for the token. Pass it with --from <secret reference> to do it without a terminal; see Secret providers.
  • An entry with an empty argv is a manual fix such as enabling KVM, and its reason gives the instructions.
  • abx image build has no terminal requirement. It takes several minutes, and when stderr is not a terminal it prints one abx: <step> line per step.

Name the box and refuse accidental creation

Always pass the box name and --no-create. A typo then fails with no-box instead of building a new VM. Setting ABX_JSON=1 makes --no-create the default, and --create overrides it for the launch that should create the box.

Creation options (--net, --allow, --agents, --access, --auth-profile, --connectors, --no-connectors) are fixed when a box is created. For an existing box they are accepted when they repeat the recorded values and every --allow host is already allowed; otherwise the command fails with fixed-option. So one command can create the box the first time and reopen it later:

abx claude fix-auth --create --net restricted --allow registry.npmjs.org --no-tty -- -p "fix the failing test"

Run a task

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

The launch is one-shot: abx waits and exits with the guest command’s status. Exit 125 means abx failed; any other status is the guest’s. Check 125 first.

Read failures

Pass --json or set ABX_JSON=1. A failure then leaves stdout empty and the last line of stderr is the envelope:

{"error":{"code":"no-box","message":"...","hint":"...","retryable":false}}

Branch on code, and follow hint when it is not null. Retry only when retryable is true, which today is lock-busy. See Error codes and JSON output.

Repeat safely

Command Repeat behavior
abx rm <box> --if-exists --json A box that is gone is listed under absent; exit 0.
abx stop <box> --if-exists --json A stopped box is already-stopped, a missing one absent; exit 0.
abx land <box> --json When the guest tip, checkout, mode and applied result still match, result is already-landed; exit 0.
abx image build --json reused: true when an intact image with the same agents and pins exists.
abx claude <box> --create <same creation options> Reopens the box. Different options fail with fixed-option.

rm refuses a running box and a Git box with unlanded commits (box-running, unlanded-commits). --force overrides both and discards the commits, so do not pass it unless the work is meant to be thrown away.

Review and land

abx diff fix-auth --stat --json
abx diff fix-auth > review.patch
abx land fix-auth --json

Review and land with the same mode (--merge, --squash or neither). abx diff --stat --json records the review as well, so land works after it. If the guest branch or your branch moved since the review, land fails with review-stale; run diff again. land refuses execution-sensitive paths with executable-paths-unconfirmed until the paths have been read and the call is repeated with --allow-executable. Leave that decision to a person; see Executable paths. Both commands fail with not-git for a scratch box. See Review and land.

Streams

Results and JSON go to stdout. Progress, notices and errors go to stderr. Capture them separately, and parse only the last line of stderr as the envelope.

Type to search…

↑↓ navigate↵ selectEsc close