Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sandbox Backends

All three backends share a common pattern: they are callPackage-able Nix functions that produce writeShellApplication derivations. Each accepts network (bool) and backend-specific customization options.

Comparison

ResourceBubblewrapContainerVM
Project directoryRead-write (bind-mount)Read-write (bind-mount)Read-write (9p)
~/.claudeRead-write (bind-mount)Read-write (bind-mount)Read-write (9p)
~/.gitconfig, ~/.sshRead-only (bind-mount)Read-only (bind-mount)Read-only (9p)
/nix/storeRead-onlyRead-onlyShared from host
/homeIsolated (tmpfs)IsolatedSeparate filesystem
NetworkShared by defaultShared by defaultNAT by default
DisplayHost X11/WaylandHost X11/WaylandQEMU window (Xorg)
AudioPipeWire/PulseAudioPipeWire/PulseAudioIsolated
GPU (DRI)ForwardedForwardedVirtio VGA
D-BusForwardedForwardedIsolated
SSH agentForwardedForwardedIsolated
Nix commandsVia daemonVia daemonLocal store
GitHub CLI configForwardedForwardedForwarded (9p)
LocaleForwardedForwardedForwarded (meta)
KernelSharedSharedSeparate

Choosing a backend

  • Bubblewrap — fastest startup, least overhead, good for day-to-day use. Shares the host kernel and network by default. Requires user namespace support.
  • Container — stronger isolation with separate PID/mount/IPC namespaces. Requires root. Good when you need namespace-level isolation without the overhead of a VM.
  • VM — strongest isolation with a separate kernel. Best for untrusted workloads. Requires KVM for reasonable performance. Chromium renders in the QEMU window rather than forwarding to the host display.

Common flags

All backends accept:

[--shell] [--gh-token] <project-dir> [claude args...]
  • --shell — drop into bash instead of launching Claude Code
  • --gh-token — forward GH_TOKEN/GITHUB_TOKEN env vars into the sandbox
  • <project-dir> — the directory to mount read-write inside the sandbox
  • Additional arguments after the project directory are passed to claude