Skip to content

Mac Runtime Reference

What a barn mac machine owns, how it is networked, and the JSON results, failure reasons, and files that scripts rely on.

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.

barn [--json|--yaml] [-v|--verbose] mac <command> [flags] [name...]

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 mac as the logged-in desktop user. Commands that talk to the runner reject root with mac_root, and a host that is not Apple Silicon on macOS 27 or later with mac_host_unsupported. Disk space and the two-VM limit are under requirements.
  • On Linux and Intel Macs, barn --help hides mac. Commands that only read local state, such as barn mac image ls, work without the runner.
  • barn mac with no subcommand runs barn 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 Homebrew libexec layouts. BARN_MAC_RUNNER overrides 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.

SettingNew machine defaultChange it with
CPUs4configure --cpu, while stopped
Memory8 GiBconfigure --memory, while stopped
Shared foldersnoneconfigure --share / --unshare, while stopped
Subnetfirst free /24configure --subnet, while stopped
Clipboard synconconfigure --clipboard, anytime; applies at the next start
Disk capacitythe prepared base’s capacity, or 100 GiB for the first basefixed
Administrator accountyour host macOS username, or barn if that is not a valid account namefixed
macOS buildthe default baserecreate --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 password file (mode 0600) and printed by barn mac password.
  • Hostnames: the guest ComputerName is <name> and LocalHostName is barn-<name> (reachable as barn-<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 --share with 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_limit and 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.

ItemValue
SubnetFirst 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
ReachabilityHost-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:

  • ssh joins the arguments after -- into one command string for the guest shell, as plain ssh does. Without a command it opens an interactive shell.
  • exec passes the program and each argument separately, so spaces, quotes, and empty arguments arrive intact. It requires a command. Wrap pipelines, redirection, and compound commands in sh -c '...'. For compatibility exec also accepts a single command string as shell shorthand; new scripts should pass separate arguments or an explicit sh -c.
barn mac ssh dev
barn mac ssh dev -- 'sw_vers; id'
barn mac exec dev -- sw_vers
barn mac exec dev -- printf '<%s>\n' 'a b' ''
barn mac exec dev -- sh -c 'sw_vers; id'
barn --json mac exec dev -- sh -c 'echo out; exit 3'

Argument rules for both commands:

  • A remote command always follows --, and its first argument must not be empty. Interactive barn mac ssh dev needs 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, with barn mac ls as the next step.
  • --json needs 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).

{
  "schema_version": 2,
  "root": "/Users/alice/.barn/mac",
  "prepared": true,
  "base": {"version": "27.2.1", "build": "26B131", "base_id": "26B131-c8269f7cdc99451b71db4104"},
  "machines": [
    {
      "name": "mac1",
      "kind": "macos",
      "state": "running",
      "ready": true,
      "ssh": "ready",
      "address": "10.10.20.10",
      "address_stable": true,
      "ssh_host": "10.10.20.10",
      "ssh_port": 22,
      "user": "alice",
      "image": {"version": "27.0", "build": "26A428", "base_id": "26A428-e16af589f4b705ca397f5b21"},
      "cpus": 4,
      "memory_bytes": 8589934592,
      "disk": {"capacity_bytes": 107374182400, "allocated_bytes": 1202647040},
      "network": {"subnet": "10.10.20.0/24", "gateway": "10.10.20.1", "address": "10.10.20.10"},
      "shares": [{"name": "src", "host": "/Users/alice/src", "guest": "/Volumes/My Shared Files/src", "readonly": false}],
      "clipboard": true,
      "pid": 2545,
      "instance_id": "b1482ffc-2da7-45d9-ace5-c5f3193a9172",
      "warnings": []
    }
  ],
  "running": 1,
  "limit": 2
}
FieldValues
baseThe default base for new machines
machines[].imageThe base this machine was cloned from
stateprepared (created, first boot not completed), starting, running, stopping, stopped, unknown
readytrue when this check verified guest SSH and passwordless sudo
sshready, pending (first boot in progress), unavailable, offline, unchecked
observedPresent when the running guest reports a macOS build different from its base
window_visiblePresent while the desktop window is open
error, warningsThe last failure recorded for the machine, and SSH issues found during this check
running, limitMachines 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.

{"name": "mac1", "action": "created", "state": "running", "ready": true,
 "address": "10.10.20.10", "user": "alice", "version": "27.2.1", "build": "26B131"}
FieldValues
actioncreated, started, running (already running), restarted, recreated, opened, configured, stopped, powered_off, already_stopped, destroyed, absent
forcedtrue 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)
windowtrue when the desktop window was opened
warningsNon-fatal notices, such as a clipboard change that takes effect at the next start

Other commands:

  • exec --json: the same schema as Linux barn exec --json (node, exit_code, stdout, stderr).
  • password --json: name and password, or {"name": "mac1", "copied": true} with --copy.
  • ssh-config --json: fragment when printing; installation status with --install or --remove.
  • logs --json: name and logs.
  • doctor --json: ok and checks[] (name, ok, detail, optional next); exits 3 if 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.

ReasonExitMeaning and next step
mac_host_unsupported3Host is not Apple Silicon or is running macOS older than 27
mac_runner_missing3Barn.app / native runner is not installed alongside the barn CLI
mac_runner_protocol3Installed Barn.app uses a different runner protocol version; reinstall matching CLI and app builds
mac_root2Invoked as root; run as the logged-in desktop user without sudo
mac_download_consent2Non-interactive macOS download requires --yes (or supply a local file with --ipsw)
mac_machine_absent4Named VM does not exist; create it with barn mac up NAME
mac_not_initialized4VM has not finished its first boot; complete initialization with barn mac up NAME
mac_not_running4ssh or exec called on a stopped VM; run barn mac start NAME
mac_running4Requested configuration change requires the VM to be stopped; run barn mac stop NAME
mac_configuration_conflict4up flags differ from the existing VM; run the suggested configure or recreate command
ssh_config_linked4~/.ssh/config is a symlink or hard link; add the printed Include line manually
mac_vm_limit6Two macOS VMs are already running on this Mac; stop the reported VM first
mac_subnet_in_use6A host route overlaps the VM’s subnet; run barn mac configure NAME --subnet auto
disk_full6Insufficient free disk space to download or install the macOS base image
mac_machine_damaged7An initialized VM slot is missing its disk or identity files (the slot directory is preserved for inspection)
mac_readiness_interrupted130barn 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-config manages ~/.ssh/barn-mac_config and a # barn-mac:include block in ~/.ssh/config, independent of the Linux # barn:include block. barn mac ssh-config --remove sets ssh_config_off in config.json, so lifecycle commands stop re-adding the Include block until you run barn mac ssh-config --install.
  • Desktop preferences: window positions live in ~/Library/Preferences/com.pgsty.barn.plist (0.9.0 used ~/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, sets ComputerName and LocalHostName, and disables idle sleep with pmset.

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.

Table reader