← Back to PRs

#7826: feat(sandbox): add Docker Sandboxes (microVM) as alternative backend

by HODL-Community open 2026-02-03 07:19 View on GitHub →
docker agents stale
## 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