README
¶
agent-microvm
Zero-cgo (CGO_ENABLED=0) network-less Linux microVM tool-execution sandbox built on Apple Virtualization.framework (github.com/tmc/apple/x/vzkit and github.com/tmc/apple/virtualization).
Designed for safe local coding agents:
- Zero network devices:
VZVirtualMachineConfigurationis built withvzkit.NetworkModeNoneand verified to havelen(NetworkDevices()) == 0. - VirtioFS staged workspace: the host workspace is cloned into a temporary staging overlay via Darwin
clonefile(2)(invoked throughpurego, with recursive-copy fallback across filesystems). The microVM only ever mounts the staged directory, never the live host workspace. - VirtioSocket (vsock) + VirtioSerial: host-guest command/output channel over
VZVirtioSocketDeviceand pipe-backedVZVirtioConsoleDeviceSerialPortConfiguration. - Reviewable diff with
--applygate: after execution,Overlay.Diff()computes added, modified, and deleted files plus a unified diff preview. Default mode is dry-run review; host files are only updated when-applyis explicitly passed. - Entitlement & asset diagnostics: detects
com.apple.security.virtualizationviacodesign -d --entitlements - --xml, supports opt-in ad-hoc self-signing viax/codesign(-auto-sign), and discovers Linux kernel/initrd assets from flags,VZ_KERNEL_PATH/VZ_INITRD_PATH, or~/.cache/{agent-microvm,vzkit}.
Files
sandbox.go—Sandboxabstraction overx/vzkit.BuildLinuxVMConfig,x/vzkit.ValidateConfig,x/vzkit.VsockManager, and pipe-backed VirtioSerial.overlay.go—Overlaystaging viapuregoclonefile(2)(APFS copy-on-write) + copy fallback, structuredDiffReport, pure-Go unified diff, and atomicApply.entitlement.go—CheckEntitlement,EnsureVirtualizationSigned(x/codesign), andDiscoverAssets.main.go— CLI entrypoint (-demo-overlay,-workspace,-kernel,-initrd,-cmd,-apply,-auto-sign,-json).main_test.go— tests for VM config validation, APFS/copy overlay diff and dry-run/apply semantics, entitlement detection, and asset discovery.
Usage
Run the self-contained overlay + VM config demo (dry-run by default):
CGO_ENABLED=0 go run ./examples/virtualization/agent-microvm -demo-overlay
Commit the demo's staged diff to its temporary host workspace:
CGO_ENABLED=0 go run ./examples/virtualization/agent-microvm -demo-overlay -apply
Run a command inside a real Linux microVM (requires a signed binary with com.apple.security.virtualization and a Linux kernel + initrd; see x/guest/initramfs for packing minimal initramfs images):
CGO_ENABLED=0 go run ./examples/virtualization/agent-microvm \
-auto-sign \
-workspace /path/to/repo \
-kernel /path/to/vmlinux \
-initrd /path/to/initrd.img \
-cmd "go test ./..."
Or sign a compiled binary manually with entitlements.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.virtualization</key>
<true/>
</dict>
</plist>
codesign -s - -f --entitlements entitlements.plist ./agent-microvm
Live Verification Results
Measured on Apple Silicon macOS (64 max vCPUs, 131072 MiB max memory, nested virtualization supported, CGO_ENABLED=0):
go test -v ./examples/virtualization/agent-microvm
=== RUN TestSandboxVMConfigValidation
main_test.go:100: ValidateWithError() (unentitled test binary): vm config: Invalid virtual machine configuration. The process doesn’t have the “com.apple.security.virtualization” entitlement.
--- PASS: TestSandboxVMConfigValidation (0.04s)
=== RUN TestOverlayCloneDiffAndApply
main_test.go:138: overlay clone method=apfs-clonefile duration=226.334µs
--- PASS: TestOverlayCloneDiffAndApply (0.01s)
=== RUN TestCopyDirFallback
--- PASS: TestCopyDirFallback (0.00s)
=== RUN TestEntitlementDetection
main_test.go:263: entitlement status: supported=true entitled=false detail="missing com.apple.security.virtualization entitlement"
--- PASS: TestEntitlementDetection (0.01s)
=== RUN TestDiscoverAssets
--- PASS: TestDiscoverAssets (0.00s)
PASS
ok github.com/tmc/apple/examples/virtualization/agent-microvm 0.422s
Entitled ValidateWithError() verification
Signing a temporary test binary with codesign -s - -f --entitlements ent.plist confirmed Apple Virtualization.framework accepts the network-less VZVirtualMachineConfiguration end-to-end:
=== RUN TestSandboxVMConfigValidation
--- PASS: TestSandboxVMConfigValidation (0.02s)
=== RUN TestEntitlementDetection
main_test.go:263: entitlement status: supported=true entitled=true detail="signed with com.apple.security.virtualization"
--- PASS: TestEntitlementDetection (0.01s)
PASS
Live -demo-overlay run
=== agent-microvm sandbox ===
Host Virt: supported=true cpus=1..64 memory=4..131072 MiB nested=true
Entitlement: missing com.apple.security.virtualization entitlement (false)
Workspace: .../host-workspace
Staging Dir: .../agent-microvm-stage-.../workspace (apfs-clonefile in 237µs)
VM Shape: cpus=2 mem=512MiB network=0 virtiofs=1(tag=workspace) vsock=1(port=5000) serial=1
VM Config: validated=false (vm config: Invalid virtual machine configuration. The process doesn’t have the “com.apple.security.virtualization” entitlement.)
Boot Assets: missing [initrd (-initrd or VZ_INITRD_PATH; optional if booting a root disk, required for initrd-only microVM)]
Overlay Diff: 1 added, 1 modified, 1 deleted (clone: apfs-clonefile in 237µs)
--- a/obsolete.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-remove me
--- a/pkg/calc.go
+++ b/pkg/calc.go
@@ -1,5 +1,5 @@
package pkg
func Add(a, b int) int {
- return a - b // bug
+ return a + b
}
--- /dev/null
+++ b/pkg/calc_test.go
@@ -0,0 +1,9 @@
+package pkg
+
+import "testing"
+
+func TestAdd(t *testing.T) {
+ if Add(2, 3) != 5 {
+ t.Fatal("bad sum")
+ }
+}
Apply Gate: dry-run (default); host workspace untouched.
Documentation
¶
Overview ¶
Command agent-microvm demonstrates a network-less Linux microVM tool-execution sandbox built on Apple Virtualization.framework (x/vzkit) with VirtioFS workspace sharing and an APFS copy-on-write staging overlay with reviewable unified diffs and an explicit --apply gate.