# Beyond git worktree: snapshots for parallel agent trials

> Source: <https://blog.boxlite.ai/beyond-git-worktree-snapshots-for-parallel-agent-trials>
> Published: 2026-12-03 03:45:55.723533+00:00

**Key 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.

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.

Giving 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.

Once 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.

Running `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.

Once 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.

On a single machine, three common ways to run parallel agent trials are `git worktree`, Docker with mounted volumes, and the embedded microVM runtime BoxLite.

| Dimension | `git worktree` | Docker + Volume | BoxLite microVM | 
|---|---|---|---|
| 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 | 
| 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 | 
| 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 | 
| Process and kernel isolation | No isolation, runs on the host | Shares the host kernel using namespaces | Independent hardware-virtualized kernel (Apple Hypervisor / KVM) | 
| 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 | 

Docker 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.

BoxLite 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.

Every persistent Box keeps its QCOW2 container disk under `~/.boxlite/boxes/{box_id}/`. BoxLite exposes two disk operations on top of it.

`box.snapshot`)
The 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.

When 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.

`clone_box` and `export`)
`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.

Once 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.

The diagram below shows the disk chain for taking a baseline snapshot after dependency setup, rolling back a failed migration, and forking two parallel trials:

``` php
flowchart TD
    A["Initial Box disk (dependencies and SQLite ready)"] --> B["Create snapshot pre-migration"]
    B --> C["Immutable snapshot layer (snapshots/pre-migration/disk.qcow2)"]
    C --> D["Active copy-on-write child disk (migration script fails)"]
    D -->|"Call snapshot.restore after stop"| E["Rebuild clean child disk (backed by same immutable snapshot)"]
    C -.-> E
    E --> F["clone_box splits shared base layer (bases/id.qcow2)"]
    F --> G["Branch A (upgrade-v1 fails and is removed)"]
    F --> H["Branch B (upgrade-v2 tests pass)"]
    H --> I["export packages .boxlite archive"]
```

Both snippets use the current Python SDK signatures from the BoxLite repo. Set `auto_remove=False` so Box state persists across stops and restores.

The 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:

``` python
import boxlite

runtime = boxlite.Boxlite.default()
box = await runtime.create(
    boxlite.BoxOptions(image="python:3.12-slim", auto_remove=False),
    name="migration-lab",
)
await (await box.exec("sh", ["-c", "pip install -r /app/requirements.txt"])).wait()
await box.snapshot.create(name="pre-migration")

res = await (await box.exec("sh", ["-c", "alembic upgrade head && pytest"])).wait()
if res.exit_code != 0:
    await box.stop()
    await box.snapshot.restore("pre-migration")
```

Note: if you want to run `exec()` again after `stop()` and `restore()`, fetch a fresh handle with `box = await runtime.get(box.id)`.

The 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:

``` python
import asyncio

trial_a = await box.clone_box(name="upgrade-v1")
trial_b = await box.clone_box(name="upgrade-v2")

exec_a, exec_b = await asyncio.gather(
    trial_a.exec("sh", ["-c", "npm install pkg@1 && npm test"]),
    trial_b.exec("sh", ["-c", "npm install pkg@2 && npm test"]),
)
res_a, res_b = await asyncio.gather(exec_a.wait(), exec_b.wait())
winner = trial_a if res_a.exit_code == 0 else trial_b
archive_path = await winner.export(dest="/tmp/exports")
```

Both `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.

BoxLite 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.

BoxLite 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.
