marsh

Agents running agents

An agent running in marsh can call registered commands to start child jobs. Each child gets a fresh container, appears under its parent in marsh jobs --tree, and stops when its parent ends. Ctrl-C cancels the whole foreground job tree.

With marsh installed and both providers configured, try this from your marsh shell:

claude -p "use your Bash tool to run: codex exec 'reply with the number 7'"
marsh jobs --tree

If Claude makes the requested call, Codex appears as its child in the tree. The child inherits its parent's project mounts and shared guest home, with its own Kit's network policy and credentials. A split can narrow its project mount to a fork. Any registered command is allowed by default, including another invocation of the same agent, subject to the limits and spawn set.

Signing in

Configure each child's provider through Docker Sandboxes, as you would for a direct call.

The task tool

marsh task-mcp is an MCP server (stdio) for an agent inside a job. Its task tool hands work to another registered agent, the way an agent's own subagent tool would, but the subagent is a marsh child job: it shows in marsh jobs --tree, and the spawn set, the limits and the parent's wall time apply as for any child. The server starts each child through the job's own in-job marsh, so children get the tool too. An agent Kit registers it in its agent's MCP configuration:

{"mcpServers": {"marsh": {"command": "/run/marsh/bin/marsh", "args": ["task-mcp"]}}}

The packaged Kits do this for each run, in CLI and ACP sessions, without writing to your project or home, and turn off the agent's own subagent tool so that delegation goes through marsh:

KitRegisters task-mcp withBuilt-in subagents
claude--mcp-config (alwaysLoad, so mcp__marsh__task is offered every turn); mcp__marsh__task, mcp__marsh__task_output and mcp__marsh__task_apply in permissions.allow, so no permission mode asks for themAgent and Workflow in permissions.deny (--settings), and a PreToolUse hook that refuses them with "use mcpmarshtask"
codex-c mcp_servers.marsh... (CLI); the ACP session's MCP servers (ACP); approval_mode = "approve" for exactly task, task_output and task_apply, so they never ask for approvalagents.enabled = false, features.multi_agent = false and features.multi_agent_v2 = false (V2 ignores agents.enabled)
piPi's registerMcpServer from a Kit extension, tools declared directly (Pi has no tool approval prompts)none to turn off
opencodeOPENCODE_CONFIG_CONTENT (mcp.marsh in CLI and ACP modes, with MARSH_TASK_MCP=reserve in the ACP proxy)permission.task = "deny"

Each Kit does this only when the job's marsh has task-mcp. In ACP mode the name marsh is then reserved for this server: the Kits' ACP proxy drops a client-supplied MCP server named marsh from every session, so no other server inherits these approvals. pi also declares its prompt verbs (pi -p), so the tool can start it.

task takes:

ArgumentMeaning
description3 to 6 words, shown to the user.
promptEverything the agent needs; it does not see the caller's conversation. At most 100 KiB.
agentA registered agent. Default: the caller's own. The tool's description lists the agents this job may start.
modelThe model the agent runs, passed to its Kit's model option (org.marsh/agent-model@1, e.g. claude --model M, codex exec -m M). Default: the agent's own. An agent without one refuses it. A family name such as astra, opus or luna stands for the agent's newest model of that family. The tool's description lists each agent's models. See Peer review.
files"shared" (default): the agent works in the caller's folder and its edits land at once. "copy": it works on a private split fork; the result includes its diff.
backgroundfalse (default) waits for the result; true returns a task id at once.

The result is the agent's final message, its exit status, the path of its whole output in the caller's container (transcript) and its job id (marsh jobs show ID). For "copy" it adds the diff (32 KiB shown; the full patch is the split's diff.patch), which is not applied until the caller asks. task_output(id, wait?, transcript?) returns a background task's result, or its status while it runs. task_apply(id) applies a "copy" task's diff to the caller's folder with marsh split apply ID LABEL --json: 3-way when it no longer applies cleanly, with conflicts named. A refusal (a limit, a name outside the spawn set) is a tool error with marsh's reason. One agent's task tool has at most 16 tasks running at once (tasks-live); finished tasks do not count, so a long session can start as many as it needs. That cap lives in the task tool, inside the agent's container, and is not a security bound: an agent that calls marsh run directly is held to the daemon's ordinary process limits instead (pool capacity, depth, job-children, tree-launch-rate, Kit VMs, the spawn set and the inherited wall time). A task's default agent is the caller's own, and it may hand work on the same way: there is no limit on claude calling claude.

Each task's job carries the label task: DESCRIPTION, and model when the call set one (Model on task jobs) (label in marsh jobs --json, marsh jobs show, and the job lines of marsh events --json), so a viewer can show the task under its caller. A description is at most 120 bytes with no control characters; without one, the prompt's first words are used. The server starts children with marsh run --label and, for "copy", marsh split --label, whose label is also its branch jobs' label. The caller's MARSH_SPAWN narrows both kinds of child, and their own children.

An agent is offered when its Kit declares non-interactive prompt verbs (com.docker.sandbox/agent-sessions@1 prompt, shown by marsh status --json under commands[].sessions); the child runs NAME VERBS... with the prompt filled in, e.g. claude -p PROMPT or codex exec PROMPT, and its stdout is the final message. A published Kit's verbs are known once marsh has read its descriptor; marsh reads every registered agent's at daemon start and after a Kit is installed or updated, so a fresh home lists every agent's models from the first job. marsh status --json lists the task-tool-v1 feature.

What a task cost

When the agent's Kit declares marsh's usage option, each task job records the tokens its agent reported. The option, org.marsh/agent-usage@1, names the words that make the agent report usage and the parser that reads its stdout:

  - type: org.marsh/agent-usage@1
    optional: true
    config:
      args: ["--output-format", "json"]
      parser: claude-json
AgentWords added after the prompt (and model)ParserWhat marsh reads
claude--output-format jsonclaude-jsonThe result object: modelUsage for each model (else usage), total_cost_usd. Its result is the final message.
codex--jsoncodex-jsonlEach turn.completed event's usage. The last agent_message item is the final message. Codex reports no cost.
pi--mode jsonpi-jsonlEach assistant message_end: its usage and usage.cost.total, and its model. The last assistant text is the final message.
opencode--format jsonopencode-jsonlEach step_finish: its tokens and cost. The last text part is the final message.

The task tool adds the words and starts the child with marsh run --usage PARSER (marsh split --usage PARSER for "copy"). The daemon reads the child's stdout with the parser as it streams and records the result on the job before the job ends. The tool still returns the agent's final message, taken from that output. Usage is never estimated. If an agent reports none, for example because it was killed first or its Kit declares no usage option, the job has no usage.

The job's own usage is usage. tree_usage is that plus every descendant's tree_usage, so a task that started its own tasks counts their tokens too. tree_usage is summed when the job ends, and updated if a child ends after it. Both appear in marsh jobs --json, marsh jobs show, and the job lines of marsh events --json. The job line for the terminal state already includes them:

{"usage": {"model": "claude-opus-5-5", "input_tokens": 6, "output_tokens": 249,
           "cached_tokens": 30177, "cache_write_tokens": 15880, "cost_usd": 0.090439,
           "source": "claude-json"},
 "tree_usage": {"input_tokens": 11, "output_tokens": 274, "cached_tokens": 41396,
                "cache_write_tokens": 31634, "cost_usd": 0.110511, "jobs": 3,
                "uncosted_jobs": 1,
                "models": {
                  "claude-opus-5-5": {"input_tokens": 8, "output_tokens": 264,
                                      "cached_tokens": 41396, "cache_write_tokens": 19384,
                                      "cost_usd": 0.110511, "jobs": 2},
                  "unknown": {"input_tokens": 3, "output_tokens": 10, "cached_tokens": 0,
                              "cache_write_tokens": 12250, "jobs": 1}}}}

This is a claude job that asked codex and claude one question each. It shows the job's own usage and the tree's. The codex child reported no cost, and no model because the task named none.

input_tokens counts input at full price only. Cache reads are counted in cached_tokens and cache writes in cache_write_tokens, never also in input_tokens. Codex counts cache reads and writes inside its input total, so marsh subtracts them. model is the model the agent reported. For Codex, which reports none, it is the model the task asked for, and absent if the task named none. cost_usd is the agent's own figure, present only when the agent reports one. In tree_usage, jobs counts the jobs that reported usage, cost_usd sums the reported costs, and uncosted_jobs counts jobs that reported tokens without a cost. A job whose usage could not all be read (the daemon reads lines of at most 1 MiB; a longer result line is skipped) has unavailable in its usage, saying why, and counts in incomplete_jobs. Such a job still counts in jobs (and, with no cost read, in uncosted_jobs), with the tokens that could be read, possibly none. models breaks the totals down by model so a mixed tree can be priced. Each entry has the same token counts, its own cost_usd (when its jobs reported one), and jobs, and the entries sum to the totals. Jobs without a known model are under "unknown". Past 32 models, the rest share "other". A task's result ends with the same two objects (usage: {...} and tree_usage ...: {...}), so the caller sees what its delegation cost. marsh status --json lists the task-usage-v1 feature.

Each "copy" task leaves a kept split (marsh splits on your Mac lists it; marsh splits rm ID removes it). When the agent closes the server (it exits), running tasks are cancelled.

Split from inside an agent

An agent can split work across private forks and read the results back as patches. From a job, each branch must be ::: LABEL CMD ARG..., naming a registered command. The child mounts its fork at the fork's own host path; the guest home is still shared.

marsh split ::: fix codex exec 'fix the typo in notes.txt' ::: review claude -p 'review notes.txt' | marsh join

This assumes notes.txt exists. Both branches begin with the same snapshot; the reviewer does not see the fixer's edits. marsh join prints one section per branch, with kit:NAME identifying the Kit and a patch for any captured changes. It never applies the patches. Use marsh join --keep if you want to inspect or apply them after join exits. See Split and join.

Shell branches (marsh split -b, split { a: ...; b: ... }) run only from your own shell. A job that asks for one is refused:

split: a: shell branches (-b, split { }) run only from the session shell

Parallel work on the same files

Inside a job, marsh fanout runs commands concurrently in that job's container, sharing its files. A registered command starts a child job; other commands use the container's own tools. Writes can race.

claude -p "run tests and lint at once with marsh fanout"

The agent can run argv branches directly:

marsh fanout ::: tests make test ::: lint make lint | marsh collect

collect prints each branch's output in the order written, and exits with the first failing branch's status. This example needs the project's test and lint Makefile targets.

From a job, branches must be ::: LABEL CMD ARG..., as for split. The fanout reference also covers shell branches and Brush blocks for use from your own shell.

Ctrl-C and cleanup

Ctrl-C in your shell cancels the foreground job's whole tree:

  1. Every job gets INT.
  2. Anything still running 10 seconds later gets KILL.
  3. marsh checks each container's deletion and records the cancellation and cleanup result. A job that had already ended keeps its completed state.
  4. Your command exits 130.

A job that ends cancels its own children the same way: INT, then KILL after 10 seconds.

If marsh cannot confirm a job ended, jobs --tree shows it as cleanup uncertain. marsh workers reset KIT removes that Kit's VM and frees the slot (Troubleshooting).

Narrowing what an agent may start

To restrict child commands, set MARSH_SPAWN in your shell to a comma-separated list of names, or none.

marsh run --spawn a,b NAME and --no-spawn do the same for one command. Nothing inside a job can widen the list.

export MARSH_SPAWN=codex
claude -p "use your Bash tool to run: shell -c true"

This limits which commands start. It does not limit what a permitted agent does to your project files.

Limits and messages

A refused call starts nothing and prints the reason on stderr. A registered-name link outside MARSH_SPAWN exits 126; other refusals, including those through marsh run, exit 125. marsh status counts refusals (processes: N running, N refused, N held).

Limit (default; name to change it)Message
64 jobs at once in the scope, all depths (daemon-jobs)capacity: 64 jobs at once in this scope; retry when one ends, or raise it with marsh config limit daemon-jobs N or MARSH_DAEMON_JOBS
64 jobs at once in one Kit VMworker VM ... is at capacity (... a Kit VM runs at most 64 jobs at once); retry when one ends
Depth 4; your command is depth 1 (tree-depth)depth limit 4: NAME would run at depth 5; use fewer levels, or raise it with ...
16 live children per job (job-children)fan-out limit 16: job ... already has 16 live children; retry when one ends, or raise it with ...
60 launches per tree in any rolling minute (tree-launch-rate); refused child calls count only up to 8rate limit: 60 launches in the last minute; retry in 12s, or raise it with ...
8 distinct Kit VMs used by live jobs in one tree (tree-kit-vms)NAME refused: tree already uses 8 Kit VMs (...); retry when one of their jobs ends, or raise it with ...
16 running tasks per task tool (tasks-live; enforced by the tool in the job, not by the daemon)16 tasks are running in this task server (limit 16 at once); wait for one ...
At least one second must remain before the parent's deadlinedeadline: parent job ... has ... ms of wall time left
A name outside MARSH_SPAWNspawn refused: NAME not in this job's spawn set (MARSH_SPAWN)
No terminal for a childinteractive child jobs are not supported yet

A child job gets no terminal. If either stdin or stdout is a terminal, marsh refuses it. Run the command as codex exec '...' </dev/null | cat. With a pipe, enable pipefail to preserve the child's failure status.

Each refusal says what to do: after capacity, fan-out limit, a full Kit VM, or the Kit VM limit, retry when a running job ends; after rate limit, retry after the time it gives. Repeated refusals consume the tree's launch budget. Depth needs a different plan, such as fewer levels. Every limit but a Kit VM's capacity can be changed without a restart, with marsh config limit NAME VALUE or its MARSH_* variable (Job limits); children share their parent's deadline.

Reading the job tree

The marsh jobs --tree columns:

  • ID: the short job id. An unambiguous prefix works with marsh jobs show.
  • STATE: queued, running, finished, failed, cancelled, or unknown.
  • RUN: from the job's start in its warm Kit VM to its end. VM boot time is not included.
  • COMMAND: the command and its arguments, cut at 64 characters.

Trees with a running job come first, then the newest. The jobs listed depend on where you run the command:

WhereJobs listed
Your marsh shellThis session's jobs
A host terminalRunning trees, trees from the last hour, and the five newest
Inside a jobThat job's own subtree

From a shell or host terminal, --all lists every recorded job in the scope. Inside a job, it still shows only that job's subtree.

A split or fanout also appears as a node, with its branch jobs below it (split). A job started in a stage downstream of join is marked (consumes split ID).

Related commands:

  • marsh jobs shows the same jobs as a flat list with a PARENT column.
  • marsh jobs show JOB adds the depth, the commands the job may start, and its children.
  • marsh results has a WALL column. It covers the whole request, from the call to verified cleanup, including any Kit VM boot.

How a child job starts

Registered commands are links in /run/marsh/bin, first on the job's PATH. Any process in the container can call one to request a child job. stdin, stdout, stderr, and exit status pass through.

bash, sh, and every other tool in the job come from the image. The in-job marsh command is also in /run/marsh/bin. It has run, split, join, fanout, collect, jobs, context, open, cloud, and task-mcp (Cloud from a job). xdg-open and open are there too (see Opening links).

Variables

Ordinary exported variables pass to jobs and their children. A job can change one for its own children. marsh filters unchanged image ENV defaults and control variables. It also drops names containing KEY, SECRET, PASS, TOKEN, CREDENTIAL, or COOKIE, plus AWS_* and *_PAT, ignoring case. This includes ordinary names such as KEYMAP. Supply provider credentials through Docker Sandboxes.

Your terminal

When you start marsh in a terminal, the shell and its jobs see which terminal it is, so programs such as Pi, Claude Code, and Codex turn on the colors and clickable links it supports. marsh copies these variables from your Mac, when they are set:

TERM, COLORTERM, TERM_PROGRAM, TERM_PROGRAM_VERSION, LC_TERMINAL, LC_TERMINAL_VERSION, ITERM_SESSION_ID, KITTY_WINDOW_ID, WEZTERM_PANE

Each value must be at most 128 letters, digits, or . _ - : + @; anything else is left out. A TERM that Linux may not know, such as xterm-ghostty or xterm-kitty, becomes xterm-256color; xterm, xterm-256color, screen*, tmux*, vt100, vt220, linux, ansi, and dumb pass as they are. With no TERM, the shell uses xterm. Nothing is copied when marsh runs without a terminal (a pipe, ACP, or MCP).

xdg-open URL, open URL, and marsh open URL in the shell VM or a job open a web link in your Mac's browser. BROWSER is set to xdg-open, so programs that open a sign-in page or a report find it.

  • Only http:// and https:// links open. A file, a path, or any other kind of link is refused: marsh: can't open file:///tmp/x from a job; open it on your Mac.
  • The link opens only while your terminal is attached to the session, from the session's own shell or a job started from it (and that job's children). From a job started without a terminal (ACP, MCP, or a split or fanout branch), or once you detach, the link is printed instead. Cloud sandboxes have no marsh xdg-open.
  • At most 3 links per session open in 10 seconds; more are printed.
  • The link is always printed on stderr, as a clickable link when stderr is a terminal, so you can open it yourself.
  • xdg-open exits 0 when the Mac opened the link, 4 when it only printed it, and 1 for a refused link.
  • marsh jobs show JOB --json lists the sites (scheme://host) a job opened under opened.

To only print links, run marsh config open-urls off on your Mac, or start the daemon with MARSH_OPEN_URLS=0.

export TICKET=ABC-123
claude -p "use your Bash tool to run: codex exec 'print the value of TICKET'"

What agents are told

Every Kit job gets /run/marsh/context.md, written for that job. It contains:

  • the job's name,
  • the commands it may start,
  • that its subagents are marsh agents, started with the task tool,
  • for agents without the tool, short examples of codex exec, marsh split, marsh fanout, and marsh jobs --tree, and that registered commands run from the project folder (or a folder under it): from anywhere else the daemon refuses the job with "run it from the project folder: cd ROOT",
  • the limits.

marsh context prints it. Outside a job, it prints the shared text with no job name or spawn set filled in.

The packaged Kits pass this context as extra instructions in both CLI and ACP sessions, for that run only. They do not write it into your project or home.

Exceptions:

  • For a Codex run, marsh's context replaces any developer_instructions in your own config.toml.
  • Management subcommands (claude mcp, codex login, ...) get nothing.
  • Other Kits can read /run/marsh/context.md or run marsh context.

Agent sandboxes and permission prompts

An agent can read, edit, or delete writable files mounted in its job, including the project (or split fork) and shared guest home. Jobs start as nonroot users without Docker or SBX sockets. Your shell VM user has passwordless sudo and the VM's Docker Engine.

The packaged Kits disable the agents' own sandboxes and permission prompts. Their namespace-based sandbox tools cannot run with the container's permissions:

  • claude runs with --dangerously-skip-permissions and --settings '{"sandbox":{"enabled":false}}'. This stops a project's sandbox.enabled, meant for your Mac, from failing Bash calls in the job.
  • codex runs with --dangerously-bypass-approvals-and-sandbox for codex and codex exec. That means approval never and sandbox danger-full-access. The default config.toml the Kit writes sets the same options.
  • Pi has no OS-level sandbox of its own. It runs with --approve so project resources load without a trust prompt.

ACP sessions (acp run claude, codex, pi) run the same Kit through its declared ACP adapter and keep these defaults:

  • Claude's ACP adapter runs Claude Code with sandbox.enabled forced off. The setting is merged into any settings the adapter passes.
  • Codex sessions start in codex-acp's full-access mode (INITIAL_AGENT_MODE=agent-full-access) unless you export another INITIAL_AGENT_MODE. The ACP client can still switch modes.

Run an agent in a split to review its project edits as a patch. The security model covers shared files and additional grants.

Next: Split and join, Fanout and collect, design: processes.

Edit this page on GitHub