{"slug": "beyond-git-worktree-snapshots-for-parallel-agent-trials", "title": "Beyond git worktree: snapshots for parallel agent trials", "summary": "BoxLite, an Apache-2.0 embedded microVM runtime, offers QCOW2 full-disk snapshots and live cloning on a single machine so parallel coding-agent trials can roll back dependencies and database state instead of rebuilding environments, with no Docker daemon or root privileges required. The runtime embeds as a library in Python, Node.js, Rust, or Go apps, uses libkrun and Hypervisor.framework on Apple Silicon macOS and KVM on Linux and WSL2, and stores each Box's QCOW2 container disk under ~/.boxlite/boxes/{box_id}/. BoxLite positions disk-level copy-on-write as more direct than git worktree, which isolates only Git-tracked files, and Docker with mounted volumes, which shares the host kernel and requires container rebuilds or docker commit exports for rollback.", "body_md": "When multiple coding agents fix bugs, upgrade dependencies, or test database migrations in parallel, `git worktree` only isolates tracked source files. `node_modules`, SQLite files, system packages, and stray background processes still sit shared on the host, so one broken run forces a full reinstall that takes longer than the tests. BoxLite is an open-source embedded microVM runtime with QCOW2 disk snapshots and live cloning on a single machine, with no Docker daemon. From its Python SDK, you can roll back dependencies and database state to a clean snapshot, then clone isolated copies for parallel trials locally.\n\nGiving each coding agent its own `git worktree` is the default way to test multiple fixes in parallel. For syntax refactors or pure unit tests with no side effects, worktrees have low overhead and near-zero switching cost.\n\nOnce a task touches the real runtime environment, worktrees break down fast. `git worktree` tracks only files under Git control, while everything else stays on the host.\n\nRunning `npm install`, `pip install`, or `apt-get install` across branches can overwrite global caches, build artifacts, or system shared libraries. If an agent runs `alembic upgrade` or edits a local SQLite or PostgreSQL data directory and breaks a migration, `git checkout` can't restore the schema or data. Local servers started by tests, bound ports, lock files under `/tmp`, and hidden config files also collide across concurrent runs.\n\nOnce a run corrupts the environment, you're stuck rebuilding a container or reinstalling dependencies from scratch. Every failed attempt triggers a multi-minute setup loop, so most of the run goes into resetting the environment.\n\nOn a single machine, three common ways to run parallel agent trials are `git worktree`, Docker with mounted volumes, and the embedded microVM runtime BoxLite.\n\n| Dimension | `git worktree` | Docker + Volume | BoxLite microVM | \n|---|---|---|---|\n| Filesystem isolation | Git-tracked files only | Writable container layer is isolated, while mounted volumes are shared by default | Independent guest root filesystem and QCOW2 container disk | \n| Dependencies and system packages | Shares host package managers and global caches | Relies on image layers, and dynamic installs pollute the container | Persisted on the container disk and reused by snapshots and clones | \n| Local database state | No isolation, needs manual backup and restore | No native branching inside volumes, and copying volumes is expensive | Included in the full-disk QCOW2 copy-on-write chain | \n| Process and kernel isolation | No isolation, runs on the host | Shares the host kernel using namespaces | Independent hardware-virtualized kernel (Apple Hypervisor / KVM) | \n| Rollback and branching granularity | Source files only | Rebuild containers or manual `docker commit` exports | Atomic full-disk snapshot, rollback after stop, live cloning while running | \n\nDocker works well for layered image builds and cross-team image distribution. In a tight agent trial loop, writing a `Dockerfile` or running `docker commit` on every attempt adds overhead, and containers still share the host kernel. When you need to isolate side effects and roll back repeatedly on a laptop or single server, disk-level copy-on-write is more direct.\n\nBoxLite is an Apache-2.0 microVM runtime that embeds into Python, Node.js, Rust, or Go apps as a library, with no Docker daemon and no root privileges. On Apple Silicon macOS, it uses `libkrun` and `Hypervisor.framework`. On Linux and WSL2, it uses KVM. Each Box runs a standard OCI image inside its own hardware-virtualized microVM.\n\nEvery persistent Box keeps its QCOW2 container disk under `~/.boxlite/boxes/{box_id}/`. BoxLite exposes two disk operations on top of it.\n\n`box.snapshot`)\nThe API supports `create`, `list`, `get`, `remove`, and `restore`. When you call `create`, the runtime writes a crash-recovery marker, pauses the microVM with `PauseGuard` and `SIGSTOP` for disk consistency, and renames the active `disks/disk.qcow2` to an immutable `snapshots/{name}/disk.qcow2`. It then creates a new copy-on-write child disk at the original path so the microVM can keep writing.\n\nWhen you delete a snapshot, the engine checks the full dependency chain across the active disk, other snapshots, and clone base disks. If any child disk still references that snapshot, deletion is refused.\n\n`clone_box` and `export`)\n`clone_box()` creates a copy whether the Box is running or stopped. During a short pause window, the runtime converts the source disk into a shared read-only base disk under `bases/`. After the source Box resumes, it generates a small QCOW2 overlay header file for each clone, so the source Box and every branch write to separate delta blocks without stepping on each other.\n\nOnce a trial branch passes, `export()` packages it into a portable `.boxlite` archive. `runtime.import_box()` can load that archive locally or onto a self-hosted `boxlite serve` instance.\n\nThe diagram below shows the disk chain for taking a baseline snapshot after dependency setup, rolling back a failed migration, and forking two parallel trials:\n\n``` php\nflowchart TD\n    A[\"Initial Box disk (dependencies and SQLite ready)\"] --> B[\"Create snapshot pre-migration\"]\n    B --> C[\"Immutable snapshot layer (snapshots/pre-migration/disk.qcow2)\"]\n    C --> D[\"Active copy-on-write child disk (migration script fails)\"]\n    D -->|\"Call snapshot.restore after stop\"| E[\"Rebuild clean child disk (backed by same immutable snapshot)\"]\n    C -.-> E\n    E --> F[\"clone_box splits shared base layer (bases/id.qcow2)\"]\n    F --> G[\"Branch A (upgrade-v1 fails and is removed)\"]\n    F --> H[\"Branch B (upgrade-v2 tests pass)\"]\n    H --> I[\"export packages .boxlite archive\"]\n```\n\nBoth snippets use the current Python SDK signatures from the BoxLite repo. Set `auto_remove=False` so Box state persists across stops and restores.\n\nThe first snippet takes a baseline snapshot after installing dependencies. If the migration or test suite fails, it stops the Box and restores the disk to its pre-migration state:\n\n``` python\nimport boxlite\n\nruntime = boxlite.Boxlite.default()\nbox = await runtime.create(\n    boxlite.BoxOptions(image=\"python:3.12-slim\", auto_remove=False),\n    name=\"migration-lab\",\n)\nawait (await box.exec(\"sh\", [\"-c\", \"pip install -r /app/requirements.txt\"])).wait()\nawait box.snapshot.create(name=\"pre-migration\")\n\nres = await (await box.exec(\"sh\", [\"-c\", \"alembic upgrade head && pytest\"])).wait()\nif res.exit_code != 0:\n    await box.stop()\n    await box.snapshot.restore(\"pre-migration\")\n```\n\nNote: if you want to run `exec()` again after `stop()` and `restore()`, fetch a fresh handle with `box = await runtime.get(box.id)`.\n\nThe second snippet live-clones two independent branches from that clean environment, tests two dependency upgrades concurrently with `asyncio.gather`, and exports the passing environment as an archive:\n\n``` python\nimport asyncio\n\ntrial_a = await box.clone_box(name=\"upgrade-v1\")\ntrial_b = await box.clone_box(name=\"upgrade-v2\")\n\nexec_a, exec_b = await asyncio.gather(\n    trial_a.exec(\"sh\", [\"-c\", \"npm install pkg@1 && npm test\"]),\n    trial_b.exec(\"sh\", [\"-c\", \"npm install pkg@2 && npm test\"]),\n)\nres_a, res_b = await asyncio.gather(exec_a.wait(), exec_b.wait())\nwinner = trial_a if res_a.exit_code == 0 else trial_b\narchive_path = await winner.export(dest=\"/tmp/exports\")\n```\n\nBoth `trial_a` and `trial_b` start stopped. The first `exec()` call boots a separate microVM for each clone, keeping filesystem edits, database writes, and process state isolated between branches.\n\nBoxLite snapshots operate at the QCOW2 disk layer. After you call `box.stop()`, `snapshot.restore()` reverts the entire disk to the target snapshot. Once the local image cache is populated, restoring a snapshot or booting a clone takes 1 to 2 seconds, close to Docker in day-to-day use, while each copy runs inside its own hardware-virtualized kernel.\n\nBoxLite runs on Apple Silicon macOS, Linux KVM, and WSL2 through the local open-source SDK or a self-hosted `boxlite serve` instance. To try this workflow, install dependencies, seed test data, and take a baseline snapshot. Run migrations and parallel trials inside clones, then export a `.boxlite` archive once a branch passes.", "url": "https://wpnews.pro/news/beyond-git-worktree-snapshots-for-parallel-agent-trials", "canonical_source": "https://blog.boxlite.ai/beyond-git-worktree-snapshots-for-parallel-agent-trials", "published_at": "2026-12-03 03:45:55.723533+00:00", "updated_at": "2026-12-03 03:45:58.696752+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools", "ai-infrastructure"], "entities": ["BoxLite", "git worktree", "Docker", "libkrun", "Hypervisor.framework", "KVM", "QCOW2", "Apple Silicon"], "also_reported_by": [], "takeaway": "BoxLite's QCOW2 full-disk snapshots capture node_modules, SQLite/PostgreSQL data directories and system packages that git worktree leaves on the shared host, letting agents restore a clean state or live-clone isolated copies for parallel trials without a Docker daemon.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/beyond-git-worktree-snapshots-for-parallel-agent-trials", "markdown": "https://wpnews.pro/news/beyond-git-worktree-snapshots-for-parallel-agent-trials.md", "text": "https://wpnews.pro/news/beyond-git-worktree-snapshots-for-parallel-agent-trials.txt", "jsonld": "https://wpnews.pro/news/beyond-git-worktree-snapshots-for-parallel-agent-trials.jsonld"}}