The Docker provider is the most common way to run Sandcastle agents locally. It creates a Docker container for each run and bind-mounts your git worktree directly into the container, so the agent writes to your host filesystem through the mount — no file syncing required.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.
Installation
Docker must be available on yourPATH. Docker Desktop is the recommended option for macOS and Windows. On Linux, install the Docker Engine package for your distribution.
Import
Basic usage
Passdocker() as the sandbox option to run():
docker() derives the image name from your repo directory name and uses your host UID/GID to match the container user.
Building the image
Before running an agent, you need a container image. Usesandcastle docker build-image after sandcastle init or whenever you modify the Dockerfile:
--build-arg AGENT_UID=$(id -u) and AGENT_GID=$(id -g) so the image’s agent user matches your host UID. This prevents permission errors on files the agent creates.
Customize the Dockerfile
Edit
.sandcastle/Dockerfile to install the tools your agent needs (e.g., npm, git, language runtimes).CLI commands
sandcastle docker build-image
Rebuilds the Docker image from .sandcastle/Dockerfile.
| Option | Default | Description |
|---|---|---|
--image-name | sandcastle:<repo-dir-name> | Docker image name |
--dockerfile | — | Path to a custom Dockerfile (build context is the current working directory) |
sandcastle docker remove-image
Removes the Docker image.
| Option | Default | Description |
|---|---|---|
--image-name | sandcastle:<repo-dir-name> | Docker image name |
Options
All options are passed todocker():
Docker image name to use for the container. Defaults to
sandcastle:<repo-dir-name>, derived from the basename of your repo directory.UID of the
agent user inside the container image. Defaults to the host UID (process.getuid()) or 1000 if unavailable. Must match the UID baked into the image at build time. A pre-flight check catches mismatches and tells you which value to use.GID of the
agent user inside the container image. Defaults to the host GID (process.getgid()) or 1000 if unavailable.Additional host directories to bind-mount into the container. Useful for mounting package manager caches (e.g.,
~/.npm, ~/.pnpm-store) or shared data directories.hostPathsupports absolute paths, tilde-expanded paths (~/...), and relative paths resolved fromcwd.sandboxPathsupports absolute paths and relative paths resolved from the sandbox repo directory.- If
hostPathdoes not exist on the host, sandbox creation fails with a clear error.
SELinux volume label applied to bind mounts. Defaults to
"z" (shared label). Use "Z" for a private label that restricts access to this container only. Pass false to disable labeling. This is a no-op on systems without SELinux (Docker Desktop on macOS/Windows, Linux without SELinux).Environment variables to inject into the container at launch time. Merged with env from the agent provider and the run-level
env option.Docker network(s) to attach the container to. Pass a single string for one network or an array for multiple. When omitted, Docker’s default bridge network is used.
"my-network"→--network my-network["net1", "net2"]→--network net1 --network net2
Branch strategy
Docker is a bind-mount provider, so it defaults to thehead branch strategy: the agent writes directly to your host working directory with no worktree indirection.
You can override the strategy on run():
{ type: "head" } (the default), the worktree directory is your current working directory, which gets bind-mounted into the container. With { type: "branch" } or { type: "merge-to-head" }, Sandcastle creates a git worktree in a temporary directory and bind-mounts that instead.
Complete example
If the image is not found locally, sandbox creation fails immediately with a message telling you to run
sandcastle docker build-image. You do not need to catch this — fix it by building the image first.