#7826: feat(sandbox): add Docker Sandboxes (microVM) as alternative backend
docker
agents
stale
Cluster:
Sandbox Enhancements and Fixes
## Summary
Adds [Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) (microVM) as an optional alternative sandbox backend alongside the existing container-based sandboxing.
Docker Sandboxes run workloads inside lightweight microVMs (via Docker Desktop 4.58+), providing stronger isolation than containers while maintaining a similar developer experience.
## Changes
- **New backend option**: `backend: "container" | "microvm"` in sandbox config (defaults to `"container"` — fully backwards compatible)
- **New module**: `docker-sandboxes.ts` — lifecycle management for microVM sandboxes (create, exec, stop, remove)
- **Config hashing**: `config-hash.ts` — detects config drift and auto-recreates stale microVMs
- **Registry integration**: sandbox registry tracks backend type for mixed environments
- **Backend detection**: `detectBackend()` in `manage.ts` reads registry, falls back to prefix heuristic
- **Prune support**: cleanup handles both container and microVM sandboxes
- **9 new tests**: lifecycle tests (CLI unavailable, create, reuse, hash mismatch, restart) + backend detection tests
- **All 33 sandbox tests pass**, TypeScript compiles clean
## Configuration
```yaml
sandbox:
docker:
backend: "microvm" # opt-in, default remains "container"
microvmTemplate: "default" # optional, defaults to "docker-sandbox-default"
setupCommand: "apt-get update && apt-get install -y git" # runs with full VM privileges
```
No config changes required for existing users — the default backend remains `"container"`.
## Requirements
- Docker Desktop 4.58+ (for `docker sandbox` CLI)
- macOS or Windows (Docker Desktop requirement)
## Files Changed (24 files, +1066/-34)
### New files (5)
- `src/agents/sandbox/docker-sandboxes.ts` — microVM lifecycle
- `src/agents/sandbox/config-hash.ts` — config drift detection
- `src/agents/sandbox/constants.ts` — shared constants
- `src/agents/sandbox/docker-sandboxes.lifecycle.test.ts` — 5 lifecycle tests
- `src/agents/sandbox/docker-sandboxes.test.ts` — 4 backend detection tests
### Modified files (19)
- Config types + zod schemas updated for `backend` field
- `context.ts` — microVM-aware workspace resolution
- `manage.ts` — backend detection + microVM orchestration
- `prune.ts` — dual-backend cleanup
- `registry.ts` — backend field in registry entries
- Exec paths updated to route through microVM when configured
## Testing
```bash
npx vitest run src/agents/sandbox/ # 25 tests pass
npx vitest run src/agents/sandbox-microvm # 4 tests pass
npx vitest run src/agents/bash-tools-sandbox # 4 tests pass
npx tsc --noEmit # clean
```
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds an optional sandbox backend (`backend: "container" | "microvm"`) that routes sandbox lifecycle and exec through Docker Desktop’s `docker sandbox` (microVM) CLI when enabled. It introduces microVM config + hashing for drift detection, updates the sandbox registry to track backend type, adjusts sandbox context/workdir behavior for microVMs, and extends management/prune flows plus tests for backend detection and microVM lifecycle.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but there is a real cleanup/regression risk for users who customize microVM name prefixes.
- Core flow changes are localized and covered by tests, but prune/backend detection currently relies on a fixed name-prefix heuristic in a way that can orphan microVM sandboxes when `microvm.sandboxPrefix` is customized. There’s also a smaller registry metadata inconsistency around `image` updates for microVM entries.
- src/agents/sandbox/prune.ts, src/agents/sandbox/registry.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23400: Onboarding: set sandbox defaults when Docker is available
by bmendonca3 · 2026-02-22
79.2%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
78.9%
#13873: fix(sandbox): prevent Windows PATH from poisoning docker exec
by alessandrorodi · 2026-02-11
78.6%
#7851: feat: secure sandbox defaults for new installs
by ichbinlucaskim · 2026-02-03
78.5%
#3907: fix(sandbox): use absolute /bin/sh path + add allowedReadPaths config
by pvoo · 2026-01-29
78.1%
#14810: fix:sandbox file path Inconsistency
by luckylhb90 · 2026-02-12
77.8%
#17402: fix:sandbox path issue
by luckylhb90 · 2026-02-15
77.7%
#11820: fix(sandbox): remap container paths in sandboxed file tools
by steflsd · 2026-02-08
77.4%
#20991: fix(sandbox): fall back to gateway UID:GID when no user is configur...
by cluster2600 · 2026-02-19
77.3%
#16509: Fix sandbox path validation rejecting Docker bind mount paths
by Clawborn · 2026-02-14
77.0%