Creating a sandbox
At minimum, a sandbox needs a name and an image. Everything else has sensible defaults: 1 vCPU, 512 MiB memory, public-only networking,/bin/sh as the shell.
Configuration options
| Option | Default | Description |
|---|---|---|
image | — | OCI image, local path, or disk image |
cpus | 1 | Number of virtual CPUs |
memory | 512 | Guest memory in MiB |
workdir | — | Default working directory for commands |
shell | /bin/sh | Shell used by shell() calls |
env | {} | Environment variables |
volumes | [] | Volume mounts (bind, named, or tmpfs) |
network | public | Network policy and port mappings |
scripts | {} | Named scripts stored at /.msb/scripts/ |
Rootfs sources
microsandbox supports three ways to provide a root filesystem. The choice affects how the filesystem is assembled and what features are available.OCI images
The most common option. microsandbox pulls the image and stacks its layers as a copy-on-write filesystem. Changes inside the sandbox don’t modify the base image. If two sandboxes use the same image, they share the same cached layers on disk.Bind mounts
Use a local directory on the host as the root filesystem directly. The guest sees the directory contents as its/. This is useful for development when you have a pre-built rootfs, or for minimal environments where you’ve assembled the filesystem yourself.
The guest agent is automatically included in the rootfs during sandbox creation, regardless of rootfs source. You don’t need to add anything to your image or directory.
Disk images
Boot from a QCOW2, Raw, or VMDK disk image. Unlike OCI images (which use a copy-on-write overlay), disk images give the guest raw block device access. See Disk Images for details.With OCI images, microsandbox stacks layers and adds a copy-on-write overlay so sandboxes share the base. With disk images, the guest gets the block device directly, so there’s no copy-on-write isolation between sandboxes using the same disk image. Each sandbox needs its own copy (or use QCOW2’s built-in snapshot/backing file support).
Replace existing
Replace a stopped sandbox with the same name instead of failing on conflict. This stops the old sandbox (if still running), removes it, and creates a fresh one.Private registry
Authenticate to private container registries and control when images are pulled.| Policy | Behavior |
|---|---|
Always | Pull the image every time, even if cached locally |
IfMissing | Pull only if the image is not already cached (default) |
Never | Never pull; fail if the image is not cached |
Config inspection coming soon
Build a sandbox configuration without booting the VM. Useful for serializing, storing, validating, or modifying configs before creation.Customizing the guest environment
If you need to run setup logic, install packages, or inject files before a sandbox starts doing real work, there are two ways to do it without building a custom image:- Scripts are files mounted into the sandbox at
/.msb/scripts/and added toPATH. Define them at creation time and call them by name withexec()orshell(). Good for multi-step setup procedures or named entry points. - Patches modify the rootfs before the VM boots: write config files, copy directories from the host, create symlinks, append to existing files, etc. The base image stays untouched since patches go into the writable layer.