PanCode
All tutorials

Safety and autonomy6 min read

Run it unattended within limits

Start a headless run with a cost ceiling and a timeout, ask read-only questions, schedule turns, and know what stops each one.

Written for
v0.9.0
Works in
Terminal · Desktop alpha
Basis
Recorded session
Updated
Terminal recording of pancode run --output-format stream-json asked to run the test check and report how many tests pass, with events written to run.jsonl and exit 0 printed; jq then reads the run_end result text: 6 passing tests and 1 failure, the absolute zero test, where kelvinToCelsius(0) throws a RangeError. The final frame shows the end of the run_end event: tool calls with nothing refused or written, safety decisions with 3 allowed and 0 blocked, an empty verify block, timings and the dispatch block.
A headless run: JSON events to a file, exit status 0, and the answer read from the run_end event that closes the stream. Terminal · v0.9.1 Recording · 0:16
Transcript
An unattended PanCode run with JSON output
Recorded with PanCode 0.9.1. Each section is the terminal screen at that moment.

== answer

~/projects/calibration-lab $ pancode run --output-format stream-json "Run the test check and report how many tests pass." > run.jsonl; echo "exit $?"
exit 0
~/projects/calibration-lab $ jq -r 'select(.type == "run_end").result.text' run.jsonl
The test check reports 6 passing tests and 1 failure. The failing test is “absolute zero”: `kelvinToCelsius(0)` throws `RangeError`.
~/projects/calibration-lab $

== run-end

  "tools": {
    "calls": 3,
    "refused": 0,
    "writes": 0
  },
  "safety": {
    "decisions": {
      "allowed": 3,
      "blocked": 0,
      "guardBlocked": 0,
      "permissionRequested": 0
    },
    "blockedAttempts": []
  },
  "verify": {
    "requested": 0,
    "checks": []
  },
  "dispatch": {
    "runs": [],
    "live": [],
    "undelivered": []
  },
  "timings": {
    "sessionReadyMs": 938,
    "firstRequestMs": 2212,
    "firstTokenMs": 5320
  }
}
~/projects/calibration-lab $
On this pageBefore you start Hand it work and walk away Read how a run ended Pick the right tool

You can start a task and leave. Headless pancode run does one turn with nobody attached, and the limits you set are enforced. This guide covers a bounded headless run, a read-only one, the timeouts that apply when you walk away from an open session, and scheduled turns.

Before you start

  • PanCode installed, with a connected model.
  • A Git repository, and a task you can state completely in one prompt.

Hand it work and walk away

  1. Put your decisions in the prompt

    The judge reads only your prompt in a headless run, so name the actions the job needs:

    Shell

    pancode run --max-cost-usd 2 --timeout 30m \
      "Fix the failing parser test, run the test check, and commit on this branch. Do not push."

    --max-cost-usd caps the priced spend this run adds. Reaching it stops the run and its workers with exit 4. Calls already in flight can pass the cap, and unpriced routes cannot be bounded, so pair it with --timeout, which exits 124 on expiry. The session ceiling, 5 USD by default, still applies.

    --require-priced refuses a run that could reach a route with no price. --max-requests <n> and --max-tool-calls <n> cap the main agent's model requests and tool calls, and each exits 4 when reached. --dry-run prints the route, tools, and limits the run would use, then exits 0 without calling a model.

  2. Ask a question that cannot change anything

    Shell

    pancode run --read-only "Which modules have no tests? Report paths."

    --read-only is an enforced ceiling on the main agent, not a request. No file outside PanCode's home changes: writes are refused, and shell commands run only in a read-only sandbox.

  3. Stream it to another program

    Shell

    pancode run --output-format stream-json "Summarize the last five commits."

    The stream opens with a session frame carrying its schema version and ends with one run_end frame. That frame holds the answer in result.text, the exitCode, the outcome, and the causes that ended the run. Read the result from it.

    When you want only the result, --output-format json prints that run_end document alone, and -o answer.txt also saves the answer to a file when the run exits 0. run --json was removed; use --output-format stream-json.

    Continue later with --continue or --resume <id>. Add --fork to branch a new session and leave the original as it was.

  4. Walk away from an open session

    In the terminal, an unanswered approval card is denied after safety.unattendedAfterMs (5 minutes by default) and the turn continues. A question takes its recommended option. Any key stops the countdown. When you return, /decisions shows what was chosen, and the exit summary counts it on an Unattended line.

  5. Schedule turns while idle

    /loop 30m Check the nightly build log and report anything new.
    /loop 5m --command make check
    /loop

    A bare /loop lists the jobs. A loop runs only while its conversation is idle and never replays missed runs. The --command form polls a program directly, with no shell.

What you should see

A finished turn with its exit code, not a parked prompt. An exit of 4 means a limit such as the cost ceiling stopped it. pancode telemetry why-stopped <session> explains a stop afterward.

Read how a run ended

Stderr names the session and prints an observed: line that counts tool calls, refusals, writes, and checks, plus a one-line summary of the outcome, requests, tokens, and cost. A script should read the exit code or the run_end frame, not the prose answer.

When --max-cost-usd meets a route with no price, stderr says the cap cannot bound it; declare connections[].pricing to fix that.

In a separate run of the first step, made for this guide apart from the session at the top of the page, Claude Haiku 5.5 on the anthropic-max route worked on a repository with one failing parser test. It split each line at the first =, ran the test check, committed on the branch, and pushed nothing.

That route carries a price estimate, so --max-cost-usd could bound it and stderr printed no unpriced-route notice. Stderr read:

pancode run: session n5iuvnc76u7o
pancode run: observed: 8 tool calls, 0 refused · 1 write · checks passed: npm run test, git status

On a route with no price, such as a gateway connection without connections[].pricing, the same command first prints pancode run: --max-cost-usd does not bound unpriced routes: <connection>/<model>; declare connections[].pricing to bound them.

The run_end frame of the third step has this shape. causes is empty on success and lists every reason, most important first, when the run failed or was stopped:

JSON

{"type":"run_end","schemaVersion":2,"mode":"main","sessionId":"<id>","exitCode":0,"outcome":"succeeded","causes":[],"result":{"text":"<answer>","artifacts":[]}}

The real frame carries more fields, such as usage, timings, and tool counts. pancode schema run-result prints the full JSON Schema.

Exit What it means
0 The run settled and succeeded
1 It failed: the model was unreachable, a worker did not deliver, or a refused call left the task undone. --fail-on-verify adds a failed --verify check
2 A usage error, including --autonomy yolo as root outside a container
3 At yolo, the safety judge blocked too many calls in a row; review the run, then --continue. Also --on-permission fail at the first request nobody could approve
4 A cost ceiling, --max-requests, --max-tool-calls, or at yolo an autonomous cap on tool calls, minutes, or tokens, stopped it; --continue resumes
124 --timeout expired; the run still settled and sealed
130, 143 Ctrl+C or a SIGTERM stopped it

Pick the right tool

When you want Use What still stops it
One bounded task pancode run at default Judge, sandbox, cost ceiling, timeout
A long job you leave running pancode run --autonomy yolo Contained by default: the sandbox and judge stay on, and a call the judge does not allow is refused back to the run. Ceilings, timeout, the loop guard, and the tool budget also stop it
A recurring check /loop in an open session Pause or stop it; needs the session to stay open

Boundaries

  • A contained command starts without credential variables and cannot open secret files, so name tools that need them. PanCode may rerun with unsandboxed: true, which the judge reviews. At unconfined yolo under safety.sandbox: required, that retry is refused.
  • yolo does not carry over from settings.yaml to a headless run. It comes only from that run's own --autonomy yolo, and it exits 2 as root outside a detected container.

By Anthony Kougkas · PanCode

Continue with the documentation