Repository navigation
feat(sandbox): add the Virtualization.framework provider (sandbox Phase 2) - #198
Merged
Merged
Conversation
…se 2) macOS backend for the sandbox: a small Swift helper (codev-vmm) plus the vz SandboxProvider that drives it. - native/vzhelper: SwiftPM executable (macOS 12+) that boots one Linux VM via VZLinuxBootLoader (kernel + initrd + virtio disk), mounts virtio-fs shares (workspace rw, bundle ro, guest-config ro), routes the guest serial console to stderr, and attaches NO network device — the guest's only egress is vsock, bridged by the helper to host unix sockets (host-to-guest server path, guest-to-host broker path). Protocol: VmConfig JSON in, newline-delimited JSON events on stdout, stop via stdin/EOF/SIGTERM. Ad-hoc signed in dev with the com.apple.security.virtualization entitlement (build:vzhelper). - vz/protocol.ts: typed wire protocol + line-buffered event reader - vz/provider.ts: availability hard-blocks below macOS 12 per plan and requires the helper binary; create unpacks the vz image tarball and clones the instance disk copy-on-write (FICLONE/APFS clonefile); start writes guest boot.json (credentials + serve args via the config share), gates on the helper's running event then the health poll, and reuses the Phase 1 TCP-to-unix forwarder; reset re-clones the pristine disk without re-downloading. Provider tests drive a fake helper process speaking the real protocol (spawn, events, unix-socket bridge, health, stop). The real binary compiles and its error protocol is smoke-verified; actually booting a VM needs the guest image from the image pipeline (parallel track). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 of the desktop sandbox: the macOS backend — a small Swift helper (
codev-vmm) driving Virtualization.framework, plus thevzSandboxProviderthat manages it. Implements the agreed design: NIC-less guest (the VM has no network device; its only egress is vsock), virtio-fs mounts, hard block below macOS 12, and the same server/broker bridge contract Phase 1 (#197) established for bwrap.The Swift helper (
native/vzhelper)A ~350-line SwiftPM executable (macOS 12+, compiles clean on Swift 6.3 toolchain in Swift 5 mode):
VZLinuxBootLoaderwith kernel + initrd + virtio block disk; cpu/memory clamped to framework limits; entropy + balloon devices; guest serial console routed to stderr so boot problems land in the provider's captured diagnostics.workspace(rw),bundle(ro, the server bundle for automatic version parity),config(ro, per-boot credentials).VZVirtioSocketDevice.connect(toPort:); guest-to-host —VZVirtioSocketListenerdials the host unix socket (where the egress broker listens). Bidirectional fd relays with proper half-close semantics.argv[1]= VmConfig JSON; newline-delimited{"event":"state"|"error"}JSON on stdout; stop via stdin command, stdin EOF (parent death), or SIGTERM.bun run build:vzhelperbuilds and ad-hoc signs with thecom.apple.security.virtualizationentitlement for dev (--universalfor arm64+x86_64); release packaging re-signs with the app identity when the desktop wiring lands.The TS provider (
src/vz/)protocol.ts— typed wire protocol + a line-buffering event reader (chunks may split/batch events arbitrarily).provider.ts—availability()enforces the plan's asymmetric policy: hard block below macOS 12 with the explanatory message (viamacosSandboxAvailability, versions read fromsw_vers), plus a helper-binary presence check.create()stages + unpacks the vz image tarball (vmlinux/initrd/rootfs.img, validated) and clones the instance disk copy-on-write viaCOPYFILE_FICLONE(APFS clonefile, plain copy fallback).start()writes the guestboot.json, waits for the helper'srunningevent, then reuses the Phase 1 TCP→unix forwarder + health gate; failures carry the helper's stderr tail (guest serial console included).reset()just re-clones the pristine disk — instant, no re-download.Verification
bun typecheckclean.bun run build:vzhelperand its error protocol was smoke-verified (cannot read config,invalid virtual machine configurationevents with correct exit codes). Actually booting a VM requires the guest image from the image pipeline (parallel track) — the README documents the guest agent contract the image must implement (mount the three tags, run the bundle perboot.json, bridge vsock 4096/8788).Notes
.build/anddist/are gitignored; the helper binary is built, not committed.🤖 Generated with Claude Code