Mac Runtime Reference
10 minute read
barn mac runs named macOS virtual machines on an Apple Silicon Mac, alongside the Linux lab but separate from it. This page defines what scripts and agents depend on: what each machine owns, how it is networked, what the commands return, how they fail, and where state lives.
Per-command syntax and options are in the macOS Command Reference; the walkthrough is macOS Virtual Machines.
Host and runner
Barn drives Apple’s Virtualization framework through Barn.app, the native macOS app bundle that ships with the Apple Silicon release and the Homebrew formula (install). The CLI and the app must come from the same build: before any VM operation the CLI checks that the app’s runner speaks protocol 2, and barn mac doctor also verifies the runner’s local code signature.
- Run
barn macas the logged-in desktop user. Commands that talk to the runner rejectrootwithmac_root, and a host that is not Apple Silicon on macOS 27 or later withmac_host_unsupported. Disk space and the two-VM limit are under requirements. - On Linux and Intel Macs,
barn --helphidesmac. Commands that only read local state, such asbarn mac image ls, work without the runner. barn macwith no subcommand runsbarn mac ls.- The CLI looks for the runner relative to its own resolved binary path, covering the app bundle (
Barn.app/Contents/MacOS/barn-mac-runner), the pkg installer, and Homebrewlibexeclayouts.BARN_MAC_RUNNERoverrides the search with an absolute, relative, or~/path.
Machines
A machine is a named macOS VM with its own copy-on-write disk cloned from a shared base image, its own private network and fixed address, an administrator account with passwordless sudo, and its own SSH keys. Machines never join the Linux lab or read its inventory, and Linux destroy and purge leave them alone.
Names are 1–32 characters: lowercase letters, digits, and internal hyphens, starting with a letter (mac1, dev, build-2). mac1 is the default name.
| Setting | New machine default | Change it with |
|---|---|---|
| CPUs | 4 | configure --cpu, while stopped |
| Memory | 8 GiB | configure --memory, while stopped |
| Shared folders | none | configure --share / --unshare, while stopped |
| Subnet | first free /24 | configure --subnet, while stopped |
| Clipboard sync | on | configure --clipboard, anytime; applies at the next start |
| Disk capacity | the prepared base’s capacity, or 100 GiB for the first base | fixed |
| Administrator account | your host macOS username, or barn if that is not a valid account name | fixed |
| macOS build | the default base | recreate --update (erases the disk) |
Disk capacity and the administrator account are fixed for the machine’s lifetime and survive recreate; create a new machine to change them. Value ranges and syntax are in barn mac up and barn mac configure.
- Administrator account: passwordless sudo, Ed25519 SSH key authentication, automatic desktop login, and Remote Login enabled. SSH password authentication is off. A random local password, needed at the lock screen and in GUI administrator prompts, is saved in the machine’s
passwordfile (mode0600) and printed bybarn mac password. - Hostnames: the guest ComputerName is
<name>and LocalHostName isbarn-<name>(reachable asbarn-<name>.local). - Shared folders: one VirtioFS device mounts every share at
/Volumes/My Shared Files/<name>in the guest. Each host source must resolve to an existing directory; symlinks are followed. Share names may contain spaces and Unicode and must be valid UTF-8 of 1–255 bytes, other than.or.., without/or ASCII control characters.configure --sharewith an existing name replaces that share’s path and mode. - Clipboard sync: plain text up to 1 MiB is synced over the machine’s SSH connection whenever its desktop window gains or loses focus. Pasteboard items marked concealed are skipped.
- Host limit: Apple runs at most two macOS VMs at a time per Mac, counted across all apps and including an in-progress base installation (requirements). Starting a third fails with
mac_vm_limitand names a machine to stop.
Networks
Each machine gets its own private /24, so its address stays the same across restarts and does not collide with another machine or the Linux lab. The machine’s runner creates the network with Apple’s shared-mode vmnet API when the machine starts and tears it down when it stops, without root or a background daemon.
| Item | Value |
|---|---|
| Subnet | First free /24 from 10.10.20.0/24 through 10.10.59.0/24 that overlaps neither a host route nor another machine, or an explicit --subnet |
| Gateway | .1, on the Mac host |
| Guest IP | .10, a vmnet DHCP reservation for the machine’s MAC address |
| Reachability | Host-to-guest routing and outbound NAT; no LAN bridging and no inbound port forwards |
If a route added later, such as a VPN, overlaps a machine’s saved subnet, start refuses with mac_subnet_in_use. Run barn mac configure NAME --subnet auto to move it to a free subnet. SSH trust survives the move because Barn pins the guest host key to barn-mac-<instance_id>, not to the IP address.
macOS Local Network privacy can block a third-party terminal or IDE from reaching the guest subnet, usually as No route to host. Allow that app under System Settings → Privacy & Security → Local Network. barn mac ssh and exec are unaffected: they run /usr/bin/ssh, and Barn’s own SSH transport goes through /usr/bin/nc, both Apple system binaries.
SSH and exec
barn mac ssh and barn mac exec connect with the machine’s own key and pinned host key and return the remote command’s exit status. They differ in how they hand the command to the guest:
sshjoins the arguments after--into one command string for the guest shell, as plainsshdoes. Without a command it opens an interactive shell.execpasses the program and each argument separately, so spaces, quotes, and empty arguments arrive intact. It requires a command. Wrap pipelines, redirection, and compound commands insh -c '...'. For compatibilityexecalso accepts a single command string as shell shorthand; new scripts should pass separate arguments or an explicitsh -c.
Argument rules for both commands:
- A remote command always follows
--, and its first argument must not be empty. Interactivebarn mac ssh devneeds no separator. - Before
--, pass Barn flags (--json,-v,--help) and at most one existing machine name; omit the name to select the default machine. Everything after--belongs to the guest command. - An unknown machine name or invalid arguments exit
2(usage) before any connection is attempted, withbarn mac lsas the next step. --jsonneeds a remote command; an interactive shell has no JSON form.
JSON output
Every barn mac command except interactive ssh supports --json and --yaml. The result goes to stdout; progress goes to stderr.
ls
In this sample, barn mac image update has made 27.2.1 the default base (base), while mac1 still runs the 27.0 base it was cloned from (machines[0].image).
| Field | Values |
|---|---|
base | The default base for new machines |
machines[].image | The base this machine was cloned from |
state | prepared (created, first boot not completed), starting, running, stopping, stopped, unknown |
ready | true when this check verified guest SSH and passwordless sudo |
ssh | ready, pending (first boot in progress), unavailable, offline, unchecked |
observed | Present when the running guest reports a macOS build different from its base |
window_visible | Present while the desktop window is open |
error, warnings | The last failure recorded for the machine, and SSH issues found during this check |
running, limit | Machines running in this BARN_HOME, and Apple’s per-host limit; the limit itself is enforced across the whole Mac |
Lifecycle results
Single-machine commands (up, restart, open, recreate, configure) return one result object. Batch commands (start, stop, destroy) return {"machines": [...]}, even for one name. When a batch partly fails, the result lists both the machines that succeeded and the failures, and the command exits 5.
| Field | Values |
|---|---|
action | created, started, running (already running), restarted, recreated, opened, configured, stopped, powered_off, already_stopped, destroyed, absent |
forced | true when the VM was powered off rather than shut down: the two-minute shutdown in stop or restart timed out, or stop --force was used (action: powered_off) |
window | true when the desktop window was opened |
warnings | Non-fatal notices, such as a clipboard change that takes effect at the next start |
Other commands:
exec --json: the same schema as Linuxbarn exec --json(node,exit_code,stdout,stderr).password --json:nameandpassword, or{"name": "mac1", "copied": true}with--copy.ssh-config --json:fragmentwhen printing; installation status with--installor--remove.logs --json:nameandlogs.doctor --json:okandchecks[](name,ok,detail, optionalnext); exits3if any check fails.
Failures
A failed command reports a stable reason and, when there is one, a next command to run. Exit codes follow the CLI exit code table; ssh and exec pass the remote command’s exit status through.
| Reason | Exit | Meaning and next step |
|---|---|---|
mac_host_unsupported | 3 | Host is not Apple Silicon or is running macOS older than 27 |
mac_runner_missing | 3 | Barn.app / native runner is not installed alongside the barn CLI |
mac_runner_protocol | 3 | Installed Barn.app uses a different runner protocol version; reinstall matching CLI and app builds |
mac_root | 2 | Invoked as root; run as the logged-in desktop user without sudo |
mac_download_consent | 2 | Non-interactive macOS download requires --yes (or supply a local file with --ipsw) |
mac_machine_absent | 4 | Named VM does not exist; create it with barn mac up NAME |
mac_not_initialized | 4 | VM has not finished its first boot; complete initialization with barn mac up NAME |
mac_not_running | 4 | ssh or exec called on a stopped VM; run barn mac start NAME |
mac_running | 4 | Requested configuration change requires the VM to be stopped; run barn mac stop NAME |
mac_configuration_conflict | 4 | up flags differ from the existing VM; run the suggested configure or recreate command |
ssh_config_linked | 4 | ~/.ssh/config is a symlink or hard link; add the printed Include line manually |
mac_vm_limit | 6 | Two macOS VMs are already running on this Mac; stop the reported VM first |
mac_subnet_in_use | 6 | A host route overlaps the VM’s subnet; run barn mac configure NAME --subnet auto |
disk_full | 6 | Insufficient free disk space to download or install the macOS base image |
mac_machine_damaged | 7 | An initialized VM slot is missing its disk or identity files (the slot directory is preserved for inspection) |
mac_readiness_interrupted | 130 | barn mac stop interrupted a first-boot SSH readiness wait |
Files
$BARN_HOME/mac
- config.jsonInstallation identity, default base image, and ssh_config_off flag
images/
ipsw/
- <build>.ipswCached Apple restore image (.partial while downloading)
- <build>.ipsw.jsonRestore image metadata and digest
base/
- <id>/Read-only, unbooted macOS base image bundle
slots/
<name>/
- state.jsonMachine record (schema 2)
- disk.asifCopy-on-write APFS disk layer cloned from the base image
- machine-id.binApple Virtualization machine identifier
- auxiliary-storage.binNVRAM / boot auxiliary storage
- id_ed25519Per-VM SSH private key
- id_ed25519.pubPer-VM SSH public key
- known_hostsPinned guest host key under barn-mac-<instance>
- passwordGenerated guest login password (mode 0600)
- runner.logPer-VM runtime log read by barn mac logs
- runtime/Global state lock and per-machine operation locks
Outside $BARN_HOME/mac:
- Control sockets:
/tmp/barn-mac-<uid>-<hash>/. - OpenSSH fragment:
barn mac ssh-configmanages~/.ssh/barn-mac_configand a# barn-mac:includeblock in~/.ssh/config, independent of the Linux# barn:includeblock.barn mac ssh-config --removesetsssh_config_offinconfig.json, so lifecycle commands stop re-adding theIncludeblock until you runbarn mac ssh-config --install. - Desktop preferences: window positions live in
~/Library/Preferences/com.pgsty.barn.plist(0.9.0used~/Library/Preferences/io.pgsty.barn.mac-runner.plist). - Inside the guest: Barn writes
~/.ssh/authorized_keys,/private/etc/sudoers.d/80-barn, and/etc/ssh/sshd_config.d/000-barn.conf, setsComputerNameandLocalHostName, and disables idle sleep withpmset.
Recovery state
An interrupted recreate leaves a recovery journal, and barn mac image prune keeps every base that journal still references until recovery cleanup finishes. While a journal is malformed, barn mac image ls, the space estimate in barn mac doctor, and pruning fail until it is repaired, and every image stays in place. If one machine’s state cannot be read, barn mac ls fails as a whole, while commands that name the other machines keep working.