VM Sandbox
The Libvirt/QEMU sandbox runs Claude inside a full virtual machine. This provides the strongest isolation — the agent has no access to your host filesystem beyond the shared project directory.
Prerequisites
Section titled “Prerequisites”libvirtandqemu-kvminstalled and running- The
libvirt-pythonoptional dependency:uv pip install open-shrimp[libvirt] virtiofsdfor high-performance directory sharing (recommended)- Your user in the
libvirtgroup
Basic setup
Section titled “Basic setup”contexts: myproject: directory: /home/you/Documents/myproject description: "My project" allowed_tools: - LSP - AskUserQuestion sandbox: backend: libvirtHow it works
Section titled “How it works”- Base image — OpenShrimp downloads an Ubuntu cloud image on first use (or uses a custom
base_image) - Overlay disk — A qcow2 copy-on-write overlay is created for each context, preserving the base image
- Cloud-init — SSH keys and provisioning scripts are injected via cloud-init
- Directory sharing — Your project directory is shared into the VM via virtiofs (preferred) or 9p
- SSH connection — OpenShrimp connects via SSH to run the Claude CLI inside the VM
VM configuration
Section titled “VM configuration”contexts: myproject: sandbox: backend: libvirt memory: 4096 # MB (default: 2048) — ceiling, unused memory returned to host cpus: 4 # vCPUs (default: 2) disk_size: 40 # GB (default: 20) — qcow2 overlay max sizeMemory uses free-page-reporting, so the VM only consumes what it actually needs — the configured value is a ceiling.
Custom base image
Section titled “Custom base image”Use your own qcow2 or cloud image:
contexts: myproject: sandbox: backend: libvirt base_image: /path/to/my-custom-image.qcow2Provisioning
Section titled “Provisioning”Run a shell script on first boot to install tools and dependencies:
contexts: myproject: sandbox: backend: libvirt provision: | apt-get update apt-get install -y nodejs npm golang npm install -g typescriptThe provision script runs via cloud-init on the first boot. If you change the provision script or toggle computer_use, OpenShrimp detects the change and automatically rebuilds the VM.
Shared directories
Section titled “Shared directories”Your project directory and any additional_directories are shared into the VM:
contexts: myproject: directory: /home/you/Documents/myproject additional_directories: - /home/you/Documents/shared-lib sandbox: backend: libvirtOpenShrimp starts a virtiofsd instance for each shared directory. Inside the VM, they’re mounted at their original host paths.
Performance
Section titled “Performance”- Cold boot: ~13 seconds. VMs are kept running between sessions for speed.
- SSH wait: Up to 60 seconds on normal boot, 90 seconds after a rebuild.
- Graceful shutdown: 180-second timeout before force-kill on
stop().
Computer use
Section titled “Computer use”Enable a desktop environment inside the VM:
contexts: myproject: sandbox: backend: libvirt computer_use: trueThe VM sandbox uses QEMU’s QMP (QEMU Machine Protocol) for mouse, keyboard, and scroll input, and the libvirt screenshot API for capturing the screen. A VNC port is auto-assigned and accessible via the /vnc command.
See the Computer Use guide for details.
Troubleshooting
Section titled “Troubleshooting”VM won’t start
Section titled “VM won’t start”Check that libvirt is running:
systemctl status libvirtdVerify your user is in the libvirt group:
groups | grep libvirtSSH connection fails
Section titled “SSH connection fails”If SSH fails after boot, OpenShrimp automatically rebuilds the VM. Check the serial log in the sandbox state directory for boot errors.
virtiofsd not available
Section titled “virtiofsd not available”If virtiofsd isn’t installed, OpenShrimp falls back to 9p directory sharing, which is slower but functional.