mattpocock/sandcastle
mattpocock/sandcastleOrchestrate sandboxed coding agents in TypeScript with sandcastle.run()
From the README
What Is Sandcastle?
A TypeScript library for orchestrating AI coding agents in isolated sandboxes:
- You invoke agents with a single
sandcastle.run(). - Sandcastle handles sandboxing the agent with a configurable branch strategy.
- The commits made on the branches get merged back.
Sandcastle is provider-agnostic — it ships with built-in providers for Docker, Podman, and Vercel, and you can create your own. Great for parallelizing multiple AFK agents, creating review pipelines, or even just orchestrating your own agents.
Prerequisites
- Git
- A sandbox provider — Sandcastle needs an isolated environment to run agents in. Built-in options:
- Docker Desktop — most common for local development
- Podman — rootless alternative to Docker
- Vercel — cloud-based Firecracker microVMs via
@vercel/sandbox - Or create your own using
createBindMountSandboxProviderorcreateIsolatedSandboxProvider
Quick start
- Install the package:
npm install --save-dev @ai-hero/sandcastle
- Run
sandcastle init. This scaffolds a.sandcastledirectory with all the files needed.
npx sandcastle init
- Edit
.sandcastle/.envand fill in your default values forANTHROPIC_API_KEY. If you want to use your Claude subscription instead of an API key, see #191.
cp .sandcastle/.env.example .sandcastle/.env
- Run the
.sandcastle/main.ts(ormain.mts) file withnpx tsx
npx tsx .sandcastle/main.ts
// 3. Run the agent via the JS API
import { run, claudeCode } from "@ai-hero/sandcastle";
import { docker } from "@ai-hero/sandcastle/sandboxes/docker";
await run({
agent: claudeCode("claude-opus-4-6"),
sandbox: docker(), // or podman(), vercel(), or your own provider
promptFile: ".sandcastle/prompt.md",
});
Sandbox Providers
Sandcastle uses a SandboxProvider to create isolated environments. The sandbox option on run() and createSandbox() accepts any provider. A no-sandbox option is also available for interactive() and wt.interactive(). Built-in providers:
| Provider | Import path | Type | Accepted by |
| ---------- | ------------------------------------------ | ---------- | --------------------------------------------- |
| Docker | @ai-hero/sandcastle/sandboxes/docker | Bind-mount | run(), createSandbox(), interactive() |
| Podman | @ai-hero/sandcastle/sandboxes/podman | Bind-mount | run(), createSandbox(), interactive() |
| Vercel | @ai-hero/sandcastle/sandboxes/vercel | Isolated | run(), createSandbox(), interactive() |
| No-sandbox | @ai-hero/sandcastle/sandboxes/no-sandbox | None | interactive(), wt.interactive() (default) |
Worktree methods (wt.run(), wt.interactive(), wt.createSandbox()) accept the same providers as their top-level counterparts. `wt.