Skip to content

SwiftVM: macOS VM plugin

SwiftVM is a prebuilt, optional macOS provider for testing inside disposable Apple Silicon macOS 27 virtual machines (darwin-arm64). Each run boots a fresh APFS copy-on-write clone of a sealed, never-booted template with no network device, executes staged jobs or native Accessibility journeys on an off-screen display, exports host-rehashed artifacts, and deletes the clone only after confirming the guest stopped.

One provider, SwiftVM (flow alias vm), covers two pages: this page covers virtual machine execution and templates, and Swift tests and coverage covers running Swift Testing suites and ingesting LLVM code coverage from guest runs. To drive a native app directly on your desktop through Accessibility, see MacOSApp.

Interactive walkthrough: Explore SwiftVM disposable macOS VM runs and artifact export.

Add SwiftVM to an application on Apple Silicon macOS:

Terminal window
reflow init --upgrade SwiftVM --collection <collection-id>

On Linux, reflow init --upgrade SwiftVM refuses and says SwiftVM needs a macOS host. See availability.

Three core invariants:

  • Apple Silicon macOS 27 host: Runs on physical Apple Silicon hardware with macOS 27 and ~100 GB of free disk for initial template setup. See host requirements.
  • Off-screen by default: Runs and provisioning use a hidden off-screen display, and a once-per-second check fails the run if any VM window appears on your desktop. See display, screenshots and clicks.
  • Never-booted master: Provisioning clones the installed master first; every command that would boot, provision, seal, verify, or run the master directly refuses it. See templates.

Configure a private binding with your sealed template bundle and APFS paths:

{
"vm": {
"provider": "SwiftVM",
"configuration": {
"templateBundle": "/path/to/sealed-template.bundle",
"runsRoot": "/path/to/runs",
"exportRoot": "/path/to/exports",
"stageRoot": "/path/to/stage"
}
}
}

Verify host virtualization support and the sealed template in a flow:

---
name: Verify macOS VM host and sealed template
providers:
vm: SwiftVM
---
### Check host virtualization support and template seal
```rfl
vm.doctor checkpoint="vm-host"
vm.template_verify checkpoint="vm-template"
```

The Reflow provider itself is prebuilt and signed ad hoc; Command Line Tools are needed for the svm host tool that installs and provisions templates.

  • An Apple Silicon Mac on physical hardware. Nested macOS virtualization is not supported, so a macOS virtual machine cannot host these guests.
  • macOS 27 on the host. Unattended provisioning uses the macOS 27 VZMacGuestProvisioningOptions API and is refused on an older host before anything is written. Guests must run macOS 27 or later.
  • Command Line Tools 27.0 on the host (Swift 6.4, SDK 27.0); provisioning installs its own copy in the guest.
  • The com.apple.security.virtualization entitlement on whatever starts a virtual machine. The released provider’s svm-guest-run helper carries it (ad-hoc signed); the svm host tool’s build script signs it the same way. Every virtual machine command refuses without it.
  • About 100 GB of free disk for first-time setup: a 26.6 GB restore image, a 26 GB never-booted master and a 34 GB provisioned copy. Installation stops below 35 GB free, provisioning needs 40 GB, and a run warns below 40 GB. Each run’s clone is an APFS copy-on-write clone on the template’s volume and grows with what the guest writes.
  • The running user logged in at the Mac’s console (the screen may be locked; Screen Sharing works). Without that login, Virtualization cannot create a macOS guest’s identity and every macOS guest fails to start, so runs and provisioning are refused up front.
  • Window-server access for the process that runs the virtual machine. The offscreen display is a window that is never shown, but it still needs the window server; a short probe checks for it before anything starts. With the console login above, runs may start from SSH or a LaunchAgent. The experimental headless display mode is not refused up front, but it is untested without window-server access; keep it out of CI.
  • For provisioning only, direct outbound HTTPS from the guest to Apple’s software update servers (swscan.apple.com, swcdn.apple.com), with no proxy. The guest downloads Command Line Tools there (several GB). The host probes both before the first boot and refuses if they cannot be reached. There is no offline option. Runs themselves need no network.

svm doctor checks these: macOS 27, Apple Silicon not virtualized, Virtualization support, the entitlement, the console login, window-server access, Command Line Tools 27 with Swift 6.4, and free space. It exits 1 when any check fails. A locked screen, a sleeping display, a newer unproven toolchain or unreachable Apple software update servers are warnings only.

A CI host needs more than a logged-in session:

  • A dedicated Mac whose user logs in automatically after every reboot. FileVault prevents automatic login, so a FileVault Mac waits at the unlock screen and runs are refused until someone logs in.
  • The CI runner started as that same user in a context with window-server access, such as a LaunchAgent in its session. svm doctor shows whether the probe passes.
  • Sleep disabled (for example with pmset).

While installing, provisioning, or running, SwiftVM prevents idle system sleep, and idle display sleep when a display view exists. It cannot wake a sleeping display or unlock a locked screen.

SwiftVM is an optional provider of the CLI release, like TLA+, ClickHouse, Lean and Bombadil, and its only platform is macOS on Apple Silicon (darwin-arm64). The release publishes it as a prebuilt package: the Go provider and its two Swift helpers, svm-observe and svm-guest-run, signed ad hoc, with svm-guest-run holding the Virtualization entitlement. Nothing is built on your Mac. Add it to an application on a Mac:

Terminal window
reflow init --upgrade SwiftVM --collection <collection-id>

reflow init downloads it once; plan and apply never download. On a Linux device, reflow init --upgrade SwiftVM refuses and says SwiftVM needs a macOS host. When an application’s lock already holds SwiftVM, a plain reflow init on Linux installs the other plugins and says that flows using SwiftVM run only on a Mac; those flows are refused there, and the rest run.

Template installation, provisioning and sealing use the source repository’s svm host tool, which you build once on the host (its README). The Reflow provider consumes an already sealed template; it does not provision one. vm.guest_run additionally needs a template provisioned with --tcc agent, whose guest agent holds Accessibility and Screen Recording.

CommandEffectWhat it does
vm.doctorobserveReports macOS version, Virtualization.framework support and maximum CPU count without booting a VM.
vm.template_verifyobserveRechecks lifecycle admission, current seal and full-content hashes without writes. An installed master is refused with TEMPLATE_MASTER.
vm.guest_runmutateRuns staged jobs in a fresh off-screen, network-less clone, exports workspace out/ with host re-hash, then confirms stop and removes the clone.

The observations launch no guest jobs and retain observation.json. An admitted template has passed seal and byte checks; admission alone does not establish boot, enrollment, permissions or successful tests.

Declare vm: SwiftVM in the flow’s providers. Its private binding has four absolute paths: templateBundle, runsRoot, exportRoot and stageRoot. doctor accepts an empty binding, template_verify needs templateBundle, and guest_run needs all four. Run and export roots share the template’s APFS volume; the stage root holds inputs as sha256/<digest>.

guest_run accepts inputs (names and SHA-256 digests), sequential jobs (argv, optional cwd/env/timeout and always-run cleanup), optional JSON files, a new exportName and a whole-call timeoutMs. Inputs are rehashed before boot. It retains job receipts, export hashes and attached PNG/JSON evidence; an unknown job is never replayed. A nonzero job exit fails the step, and unconfirmed cleanup can never pass. The source repository’s generated guest_run command guide defines the full schema and limits.

For native UI journeys, stage the separate MacOSApp guest executor and your app by digest. The executor runs inside the guest agent’s permission chain, checks both grants in every clone, drives the app and records accessibility trees, window captures and cleanup. This does not install the desktop MacOSApp provider; see guest execution.

A template goes through install, copy, provision, seal and verify:

  1. Install. svm template install --ipsw <file> --bundle <master> creates the master from an Apple restore image with the public VZMacOSInstaller (about 4 minutes and 26 GB on one host). It exits 0 when complete, 4 when cancelled, 5 when the outcome is unknown, 2 when it failed and 1 on a setup error. A partial install is never retried or overwritten.
  2. Master. The master is never booted, provisioned, sealed, verified or run. Install marks it three ways: a MASTER.json inside it, an install journal beside it, and an entry in the host’s master registry (~/Library/Application Support/reflow-svm/masters.json). The registry matches the directory’s inode and birth time, so a renamed master, or one moved on the same volume, stays refused. A cp -c -R copy gets a new inode and is accepted as a copy. Do not count on moving a master to another volume to make it usable: inode numbers are unique only within a volume, so a directory there with a matching inode is refused, and a master moved together with its install journal stays refused. When a registry entry refuses a directory, keep the entry and use a copy, as the refusal says. Provisioning, seal, verify, runs, the console (even with --allow-first-boot) and vm.template_verify all refuse it. svm template mark-master --bundle <master> lists a master that predates these markers before you rename or move it; it boots nothing and writes nothing into the master.
  3. Copy and provision. svm template provision --from <master> --bundle <new> --guest-package <dir> first makes an APFS clone of the master on the same volume, without writing anything into the master, then provisions that copy. <dir> is the guest package: the guest agent app, its LaunchAgent and installer with their SHA-256 sums, made by SwiftVM’s packaging script into a new directory. You can also make the copy yourself with cp -c -R <master> <new> and omit --from. Provisioning boots the copy for the first time with VZMacGuestProvisioningOptions: a user with a random password, automatic login and remote login. It waits until the guest is ready, disables password SSH and proves it is refused, installs Command Line Tools and the guest agent, grants its Accessibility and Screen Recording permissions through System Settings on the VM display (--tcc agent, the default), then disables the SSH server, so clones have no port 22 listener. --tcc none skips the grants and cannot produce a guest_run-ready template. Provisioning succeeds only when the guest confirms it has stopped; otherwise the host forces a stop and the copy can never be sealed. Provisioning can take half an hour, mostly the Command Line Tools download.
  4. Seal. svm template seal records a full-content SHA-256 manifest of a provisioned template.
  5. Verify. svm template verify and every clone refuse a template unless its history is safe, its install is complete, and its manifest is the current seal with no boot after it.

Provisioning ends with one of these exit codes:

ExitMeaning
0Provisioned.
1Refused before the first boot; the copy is still unbooted.
128 + signalInterrupted (SIGINT, SIGTERM or SIGHUP) before the first boot; the preparation is undone and the copy is still unbooted.
2Booted and stopped cleanly, but not provisioned.
3The stop was not confirmed, including an interrupt before the guest was ready or a second interrupt.

After exit 2 or 3 the copy cannot be reused: start again from a new copy of the master. When --from made the copy, an interrupt or refusal before the first boot removes that copy and leaves the master untouched.

Refusals print a route that works when followed, such as a cp -c -R copy or --from, and never ask you to remove a registry entry: an entry that refuses a directory is protecting the master it records. If the registry cannot be read, every template is refused until its JSON is repaired or restored from a backup; deleting, emptying or moving it aside would release every master it lists.

History is fail-closed. A boot without a confirmed guest stop, a power-off from the host, or torn or unknown history makes the template permanently unusable for sealing and cloning. History is never repaired automatically; build a fresh template from the master instead. svm template console boots a provisioned template for manual inspection only. Any console boot means the template must be sealed again before the next verify or run. End the session with a shutdown inside the guest: a power-off from the host makes the template unusable for good. Closing the console window or pressing Ctrl-C only asks the guest to stop, and logged-in guests ignore that request, so the host powers the virtual machine off after a 120-second grace period.

svm run --bundle <template> --runs <dir> --fixture <dir> gives each run its own clone with a fresh machine identifier and MAC address, a read-only shared folder for its inputs, and no network device. --network adds NAT networking, through which the guest can also reach services listening on the host, the local network and the internet; no current scenario needs it. Before the boot, the template and its clone are re-hashed against the seal, and runs on one template wait for each other.

A stop is confirmed only when the guest reports it has stopped, or a forced stop completes with the machine stopped. The clone is removed only after a confirmed stop; otherwise it is kept with recovery notes. The template is never modified.

The svm host tool ends each run with a verdict and an exit code:

ExitVerdict
0Passed, with cleanup confirmed.
1Setup error before the virtual machine started.
2A required check failed.
3Cleanup or the report could not be confirmed.
4Incomplete: nothing failed, but something is unproved.
64Usage error.
130, 143, 129Interrupted (SIGINT, SIGTERM, SIGHUP), with cleanup confirmed. A dropped terminal’s SIGHUP is handled like SIGTERM.

The default selection, intended as the CI gate, runs the passing test suite and the GUI proof below (the passing suite only with --display headless). An svm fixture run that requests coverage never passes: at best it ends incomplete (exit 4); see Swift tests and coverage.

--display selects one of three modes:

ModeBehavior
offscreenDefault for runs and provisioning. A public VZVirtualMachineView in a borderless window that is never shown, under an app with no Dock icon that never activates. Nothing appears on the desktop.
headlessNo view: no screenshots, no input and no GUI checks. Experimental.
windowA visible titled window. Used only when you ask for it: --display window, svm run --console to log in to a run’s clone by hand, or svm template console, whose default is a window because it is for manual inspection.

Screenshots come from the virtual machine view’s own framebuffer. They need no ScreenCaptureKit and no Screen Recording permission. The view is public API, but reading its frames this way depends on undocumented behavior of VZVirtualMachineView, so a black or missing frame is recorded as such and never counted as success. Each run keeps full-resolution PNGs and an evidence.json with their SHA-256 hashes, dimensions, capture method, black-frame flags and the host’s lock and display-sleep state.

Clicks are mouse events delivered to the hidden view on the host, so the guest needs no Accessibility or Screen Recording permission. Key events are sent the same way; provisioning verifies typed text and Return in the guest. Modifier-key behavior is not fully proven. Positions map from the guest’s screen points by fraction of the guest-reported screen size.

With the offscreen display, the required host-window-hidden check reads the host’s window list every second, from the moment the display exists until the virtual machine stops, and looks for the tool’s own windows. The display is not hidden, and the check fails, when any sample shows one of those windows on screen, when the window list cannot be read, when there are no samples, when the tool is ever a regular or active app, or when its app state cannot be read on every sample, or on more than one sample and more than 10% of them. Provisioning samples the same way from its first preparation step and fails with exit 2 when the display was not hidden.

The GUI proof launches a sample AppKit counter app in the guest. Besides its label and buttons, the app draws a count marker: a 12 by 2 grid of black and white cells that encodes the current count, built so that a blank or uniform area never decodes as a number. The app reports where its window, label, marker and buttons are; that layout only tells the host where to look. The host takes a screenshot, waits a second and takes a control screenshot without any input, clicks the app’s increment button, then takes a screenshot after the click.

The host then re-reads those screenshots and decodes the marker in each one itself. The proof requires the count to read 0 before the click, 0 in the control screenshot and 1 after it. A marker that cannot be decoded, for example because the window closed or something covers it, leaves the proof unproved, not passed; any other count fails it. The label must also stay essentially unchanged in the control pair and change after the click, and the change must be local: almost nothing may change outside the app window, or inside the window outside the label, marker and buttons. An ignored click that happens to coincide with an unrelated repaint therefore fails. A second required check, gui-app-after-input, confirms the app is still running as the same process after the click.

  • Platform: Apple Silicon macOS 27 hosts only (darwin-arm64); Linux and Intel Macs are unsupported.
  • Tooling: Template installation and provisioning use the svm host tool built from source; provisioning requires direct outbound HTTPS for Command Line Tools. Guests run Command Line Tools (Swift Testing) rather than Xcode (XCTest/.xcresult). Keep headless display mode out of CI.
  • Trust boundary: Untrusted job code is not supported. Jobs run as the guest’s admin user, so a job can replace the guest agent and fabricate results; host re-hashing verifies intact transfer only. Keep provisioned templates on the host that created them (clones share the template’s auto-login admin credential).
  • Host display input: Narrower than the MacOSApp guest executor; do not infer support for arbitrary desktop automation or every system key.
  • Background activity notifications: Every clone shows a persistent “App Background Activity” notification for the guest agent. A notification that appears or is dismissed between the control screenshot and the post-click screenshot fails the GUI proof (never creating a false pass).
  • Crash recovery: If the host process is killed or crashes, the clone is left behind without a report and requires manual cleanup.
  • Public APIs only: SwiftVM uses only public APIs—no private Virtualization.framework input, VNC/NVRAM access, TCC database edits, or SIP changes. Guest permissions are granted through System Settings during provisioning. Screenshot capture uses VZVirtualMachineView (see display, screenshots and clicks).