Architecture
microagent is a thin CLI on top of pkg/vmkit. vmkit builds requests,
dispatches them through a backend supervisor, and writes back structured
responses. Each host OS uses one backend.
your program └─ microagent (cmd/microagent) └─ vmkit (pkg/vmkit) ├─ Firecracker backend (Linux, in-process Go) └─ microagent-applevf-supervisor (macOS, Swift JSON exec)
OCI image ──► pkg/rootfs ──► ext4 disk ──► VMPieces
Section titled “Pieces”cmd/microagent— the CLI. Parses flags, builds avmkit.Request, hands it to the dispatcher, prints thevmkit.Response.pkg/vmkit— request/response types, supervisor client, dispatch logic. The shared shape both backends speak.pkg/rootfs— OCI image to ext4 rootfs builder. Pulls layers viaoras-go, writes a sized ext4 image withmke2fs.supervisors/applevf— Swift executablemicroagent-applevf-supervisor. Reads one JSON request from stdin, talks to Apple Virtualization.framework, writes one JSON response to stdout.cmd/microagent-guestinit— small guest init that mounts attached disks and runs--setup/--exec.
Lifecycle of a microagent run
Section titled “Lifecycle of a microagent run”- CLI parses flags into a
vmkit.Request(kernel path, rootfs path, disks, memory, CPUs, identity). - If a kernel or rootfs is missing, vmkit triggers
pkg/rootfsor the kernel installer. - The dispatcher selects the host backend.
- Firecracker boots in-process; Apple VF spawns the supervisor and pipes JSON.
- Guest init runs
--setupthen--exec. - State changes are emitted as JSON events. State files live under
--state-dir(default~/.microagent/...). - On
--keep, the workspace stays. Otherwise vmkit issuesstopanddeleteto clean up.
Why a separate supervisor on macOS
Section titled “Why a separate supervisor on macOS”Apple Virtualization.framework is host-native and Swift-only. Running it from a separate process lets every language with a JSON parser drive macOS VMs without linking Swift, and isolates the bridge from the rest of the CLI.
The protocol is documented at Apple VF supervisor.