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.
createSandbox() creates a git worktree and starts a sandbox container once, then returns a Sandbox handle you can call .run() on as many times as you need. All runs share the same container, so installed dependencies, build artifacts, and file-system state persist between calls. Use it when you need an implement-then-review pipeline, or when the container startup cost of calling run() repeatedly would be significant.
Use run() instead when you only need a single one-shot invocation — it handles the sandbox lifecycle automatically.
Import
Signature
Basic usage
Automatic cleanup with await using
createSandbox() returns an object that implements Symbol.asyncDispose. When you declare the variable with await using, the sandbox is automatically torn down when the block exits — even on error. If the worktree has uncommitted changes at close time, it is preserved on disk rather than deleted.
Multi-run implement-then-review example
.run() calls accumulate on the same branch. The sandbox container stays alive between runs.
Manual close with CloseResult
CreateSandboxOptions
The explicit branch name for the sandbox worktree. The worktree is created on this branch (or the branch is created from HEAD if it does not exist).
Sandbox provider — for example
docker(), podman(), or a custom provider. See sandbox types.Host repo directory used as the anchor for
.sandcastle/ artifacts and git operations. Relative paths resolve against process.cwd().Lifecycle hooks grouped by execution location. Hooks run once at creation time. See SandboxHooks.
Host-relative file paths to copy into the worktree at creation time (for example
[".env"]). Not supported with isolated providers — those handle file transfer internally.Sandbox object
The Sandbox handle returned by createSandbox() exposes the following properties and methods.
The branch the sandbox worktree is on.
Absolute host path to the worktree directory.
Invoke an agent inside the existing sandbox. The container stays running between calls.
Launch an interactive agent session inside the sandbox. The agent TUI is attached to your terminal.
Tear down the container. If the worktree has uncommitted changes it is preserved; otherwise it is removed.
Called automatically by
await using. Delegates to close().CloseResult
Host path to the preserved worktree directory. Set when the worktree had uncommitted changes at close time.
undefined when the worktree was clean and has been removed.