Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mattpocock/sandcastle/llms.txt
Use this file to discover all available pages before exploring further.
RunOptions is the single options object passed to run(). Every field except agent and sandbox is optional. The table below lists all fields, their types, defaults, and descriptions.
Required fields
Agent provider — for example
claudeCode("claude-opus-4-7"), pi("claude-sonnet-4-6"), codex("gpt-5.4-mini"), or opencode("opencode/big-pickle"). Pass provider-specific options (like effort) as a second argument.Sandbox provider — for example
docker(), podman(), or vercel(). Provider-specific config (image name, mounts, env) lives inside the provider factory call. See sandbox types.Prompt
Inline prompt passed to the agent literally. Mutually exclusive with
promptFile. No {{KEY}} substitution, no !`command` expansion — build the string in JavaScript if you need dynamic values. Passing promptArgs alongside an inline prompt is an error.Path to a prompt file. Mutually exclusive with
prompt. Always resolves against process.cwd(), not against cwd — pass an absolute path when you set a custom cwd to avoid ambiguity. Supports {{KEY}} placeholder substitution and !`command` shell expression expansion.Key-value map for
{{KEY}} placeholder substitution in the prompt file. Only valid with promptFile. Sandcastle automatically injects SOURCE_BRANCH and TARGET_BRANCH — passing either of those as keys is an error.Execution control
Maximum number of agent iterations to run. The loop stops early if
completionSignal is matched. Setting this above 1 is incompatible with resumeSession and with structured output.Substring or array of substrings the agent emits to stop the iteration loop early. Matched via
String.includes against agent output. The matched string is returned as result.completionSignal.Idle timeout in seconds. Resets whenever the agent produces any output. If the agent is silent for this long, the run fails.
Resume a prior Claude Code session by its session ID. The session JSONL file must exist on the host at
~/.claude/projects/<encoded-path>/sessions/<id>.jsonl. Incompatible with maxIterations > 1. Only the first iteration receives the --resume flag.An
AbortSignal that cancels the run when aborted. If already aborted at entry, run() rejects immediately without any setup. Aborting mid-iteration kills the in-flight agent subprocess and cancels lifecycle hooks. The worktree is preserved on disk. The rejected promise surfaces signal.reason directly.Repository and branch
Host repo directory — replaces
process.cwd() as the anchor for .sandcastle/ artifacts (worktrees, logs, env, patches) and git operations. Relative paths resolve against process.cwd().Controls where the agent’s commits land. Defaults to
{ type: "head" } for bind-mount providers and { type: "merge-to-head" } for isolated providers.{ type: "head" }— agent writes directly to the host working directory. No worktree is created. Bind-mount providers only.{ type: "merge-to-head" }— Sandcastle creates a temporary branch, the agent commits there, and changes merge back to HEAD when done.{ type: "branch", branch: "agent/fix-42" }— commits land on an explicitly named branch.
Host-relative file paths to copy into the worktree before the sandbox starts — for example
[".env"]. Not supported with branchStrategy: { type: "head" } because in head mode the host working directory is mounted directly.Lifecycle and setup
Lifecycle hooks grouped by where they run. See SandboxHooks.
Override default timeouts for built-in lifecycle steps. Currently supports
copyToWorktreeMs (default: 60_000). See Timeouts.Logging and display
Display name for the run, shown as a prefix in log output. Also used to disambiguate log file names in multi-agent workflows.
How to record progress and agent output. Two modes:
{ type: "file", path: ".sandcastle/logs/my-run.log", onAgentStreamEvent?: (event) => void }— write to a log file. The optionalonAgentStreamEventcallback fires for each text chunk and tool call the agent produces, for forwarding to external observability systems. Errors thrown by the callback are swallowed.{ type: "stdout" }— render an interactive UI in the terminal using Clack.
{ type: "file" } with an auto-generated path under .sandcastle/logs/.Structured output
Structured output definition. When provided, Sandcastle scans the agent’s stdout for the configured XML tag after the iteration completes, parses and validates the content, and returns it as
result.output.Output.object({ tag: "result", schema: z.object({...}) })— JSON content validated against a Standard Schema (Zod, Valibot, etc.). The inferred type flows through toresult.output.Output.string({ tag: "summary" })— tag contents returned as a plain trimmed string.
maxIterations must be 1 (the default), and the resolved prompt must contain the opening tag literal. See Output.