The host command is anyswarm. Run it without arguments for Quickstart, or add
--help to a command for its options. The Worker image separately supplies
swarm for Agent calls to Services over the Bridge.
Host commands
| Workflow | Commands |
|---|---|
| Prepare and verify local execution | anyswarm setup, anyswarm doctor --smoke |
| Upgrade the installed CLI | anyswarm update prints the npm command for the current global installation. Run the printed command from the same Node/npm environment. |
| Run an editable Harness | anyswarm run ./project.ts --cwd ./input --config ./config.ts --prompt "Inspect the project" |
| Run a built-in Harness or connect a client | anyswarm --harness subagents --prompt "Read README.md" --output-dir ./runs, or anyswarm --harness subagents --mode rpc |
| Export source and the exact SDK | anyswarm eject example --dir ./my-harness |
| Inspect records or recover pending cleanup | anyswarm trace --root ./runs --port 8787 --open, anyswarm recover --run-dir <dir> --config <module> |
anyswarm --version prints the installed package version. See Quickstart for local setup, explicit existing OpenSandbox connections and npm installation.
Run a Harness
Pick a built-in name, an explicit TypeScript or ESM module, or an installed npm
package resolved from the invocation directory. Built-ins are subagents,
autoresearch, taskpool, peermesh, substrate, lead-worker, notes and
messages. The project defaults to the invocation directory. --config
selects a trusted module and --output-dir selects the Run records root.
Set --cwd to capture a different project.
A one-shot Run starts from the supplied prompt. run supplies a default prompt
when a source Harness is launched without one. On a terminal, stdout shows Run
and Agent milestones, visible Service changes, exported artifact paths, cleanup,
and the command to view Trace. Redirect stdout for a single JSON result or
launch error. Source and Harness diagnostics go to stderr. run also executes
ordinary trusted source scripts with their original arguments.
For multiple turns, start --mode rpc, wait for the JSONL ready frame, and
send a run request with cwd and prompt. Use --lifetime interactive if
the Harness supports it and --interaction questions if the client can answer.
The stream carries replies, events and the final result on stdout. Use
describe for available controls and stop to initiate cleanup. HarnessSession example
After ejecting, run npm install inside the export and start the editable
entry with its local CLI, for example npm run start -- --prompt "Inspect the project".
See Code and Personal
for advanced SDK examples.
AutoResearch
AutoResearch is the non-interactive research showcase. It starts equal peers in private Sandboxes, coordinates them through the research Service, and records train, candidate and final evidence for Trace Viewer.
anyswarm --harness autoresearch --config ./research.ts --prompt "Your objective" --output-dir ./runs
Use the AutoResearch guide to prepare the pinned FrontierCS-2 demo or export and edit the Harness.
Unified environment variables
Built-in CLI Harnesses (subagents, taskpool, notes, messages) share one consistent set of host environment variables (explicit configuration takes precedence over process environment and the saved connection):
| Variable | Default | Purpose |
|---|---|---|
ANYSWARM_MODEL_URL |
(required) | Streaming OpenAI Responses-compatible endpoint ending in /v1/responses |
ANYSWARM_MODEL_TOKEN |
(optional) | Upstream bearer token kept strictly on the host Model Gateway |
ANYSWARM_MODEL_PROVIDER |
openai |
Model provider name for Pi/Codex routing (any custom provider supported) |
ANYSWARM_MODEL_ID |
gpt-5.4 (Pi) |
Model ID sent to the upstream endpoint (required when ANYSWARM_EXECUTOR=codex) |
ANYSWARM_EXECUTOR |
pi |
Executor backend: pi or codex |
ANYSWARM_WORKER_IMAGE |
Current SDK local Worker | Explicit compatible Worker supplied by the operator |
OPEN_SANDBOX_ENDPOINT |
http://127.0.0.1:8080/v1 |
OpenSandbox Lifecycle endpoint, overriding the connection saved by anyswarm setup |
OPEN_SANDBOX_API_KEY |
(saved connection) | OpenSandbox management credential |
ANYSWARM_RUNTIME_PUBLIC_URL |
(saved/local discovery) | Shared Sandbox-reachable Runtime callback URL (supports reverse-proxy prefixes) |
ANYSWARM_ADVERTISE_HOST |
(local discovery) | Advanced callback host override |
PeerMesh,Substrate, andLead-Workerrequire additional facility variables (such as Gitea, Mattermost, Board MySQL DSN, or Lean paths). See their individual pages under Harnesses.
Container CLI (swarm)
Inside every Sandbox, swarm communicates with the host Service Bridge using Core-injected protected environment variables (ANYSWARM_BRIDGE_URL, ANYSWARM_BRIDGE_TOKEN, ANYSWARM_BRIDGE_CONTRACT_VERSION=2):
# Discover permitted Services and inspect full JSON schemas
swarm service list
swarm service view <service-id> --json
# Invoke a permitted operation (named flags, --input file, or --stdin)
swarm <service> <operation> --input payload.json --request-id <unique-id>
swarm <service> <operation> --stdin --request-id <unique-id>
swarm service invoke <service-id> <operation> --input payload.json --request-id <unique-id>
# Built-in agent Service (when granted in Profile.services.agent)
swarm agent spawn --profile worker --text 'Audit src/parser.ts' --fork true --request-id child-1
swarm agent get <agent-id>
swarm agent send <agent-id> --text 'Focus on error paths' --mode steer --wake-if-idle false --request-id steer-1
swarm agent stop <agent-id> --request-id stop-1
swarm service invoke writes a ServiceReply to stdout and exits 0 for ok: true or 1 for ok: false. Read .result for the business value. Use .meta to identify the Bridge attempt and outcome when available. Named compatibility commands keep their historical output and exit conventions.
swarm exit codes
| Exit code | Meaning |
|---|---|
0 |
Operation succeeded |
1 |
Transport, Bridge, or Service runtime error |
2 |
CLI syntax or JSON Schema contract error |
3 |
Checker completed successfully with a business fail verdict (fail / failed / source_failure / mathematical_failure / incorrect) |
Repository foreground runners (from source)
When working directly inside a built anyswarm source checkout, two additional developer scripts drive configured taskpool or peermesh fixtures over JSON-line stdin (status, kickoff, input, wait, stop) and inspect saved reports offline:
node dist/scripts/run-harness.js --config <host-config.ts>
node dist/scripts/read-harness-result.js --run-directory <dir> --runtime-id <id>
runInput, runWithReport and the legacy readHarnessResult reader are available from the @anyswarm/core package root.
anyswarm recover (durable cleanup recovery)
anyswarm recover --run-dir /private/runs/original-runtime-id --config /private/recovery.ts
The config module default-exports either the original Runtime options object or a zero-argument async factory returning it. This command performs cleanup-only recovery, calls close(), prints the receipt, and exits 0 only when cleanup completes. Recovery requires same-host, same-boot exclusive writer ownership and matching durable persistence settings; unresolved resources remain tracked in the ledger until reconciliation confirms stop and deletion. Retry failed required exports before the reported expiresAt. See Runtime durable recovery.