Test Your Mac Setup Script or Ansible in a Throwaway macOS VM
Test a Mac setup script, dotfiles or Ansible playbook against a throwaway macOS VM that resets every run. Steps for Hermitbox on Apple silicon, with SSH.
GuideUpdated 9 min read
On this page
You want to run your Mac setup script, dotfiles bootstrap or Ansible playbook, but not on the Mac you work on. You also want to run it again tomorrow on a clean machine without rebuilding anything. A disposable macOS VM does that. This guide uses Hermitbox, but the idea works in any VM app that can discard changes.
You need an Apple silicon Mac on macOS 14 Sonoma or later, because macOS guests don't run on Intel Macs. Hermitbox is part of MacSuite, and each app has a 7-day trial without a key.
Why a VM and not your own Mac
Setup scripts change things that are hard to undo: Homebrew, shell config, defaults write settings, login items, sudo rules. Re-running them on a Mac that already has those changes proves little. You can't tell whether the script works from scratch or only works because an earlier run left something behind.
| Option | Isolates system-wide changes? | Resets cleanly? |
|---|---|---|
| Second user account | No (Homebrew, apps and sudo settings still touch your real Mac) | Delete and recreate the account |
| Snapshot restore in a VM | Yes | Yes, rolls back to a named state |
| Disposable run in a VM | Yes | Yes, discarded when the VM stops |
A second user account is free and enough for dotfiles that only touch a home folder. For anything that installs software or changes system settings, use a VM.
Build the base VM once
- Choose File ▸ New VM… (⌘N) and pick macOS.
- Choose a source. Latest macOS downloads the newest version your Mac supports. Choose a Version… lists older releases from Apple. Use an IPSW File… takes a file you already have.
- On Name and Size, name it
mac-base, accept the recommended sizes (4 cores, 8 GB, 80 GB when your Mac has room) and click Create. The macOS minimum is 4 GB of memory and 64 GB of disk. Disk space is used only as the VM fills it. - Wait for the download and install. Hermitbox says macOS takes about ten minutes. The VM ends at macOS Setup Assistant.
- Create the user account. Use a throwaway password you don't use anywhere else, because you will type it for
sudo. - Turn on SSH in the VM. In the VM, open System Settings, go to General, then Sharing, and switch on Remote Login. Apple's support article on Remote Login covers the Info button and the "Allow access for" setting.
- Optional: double-click the Hermitbox Guest disk on the VM's desktop and install it. It adds clipboard sharing and reports the VM's IP address and macOS version to Hermitbox.
- Copy your SSH key over, so test runs never ask for a password (see the next section for finding the IP).
ssh-copy-id admin@192.168.64.5This appends your public key to the VM's ~/.ssh/authorized_keys. It assumes you already have a key in ~/.ssh, and it asks for the VM account's password once. Replace admin and the example address with your account and the VM's IP. Do this before the first test, and every disposable run starts with the key in place.
Decide what "clean" means
A brand-new Mac has no Command Line Tools. Ansible needs Python on the target, and without the Command Line Tools /usr/bin/python3 only triggers an installer prompt. You have two choices:
- Faithful base: leave the VM bare and let a bootstrap shell script run
xcode-select --installand the rest of your real first-boot routine before Ansible. This tests the whole path. - Faster base: run
xcode-select --installin the VM before you finish the base. Runs start sooner, but that step is no longer tested.
Pick one and keep it. Otherwise a failing run won't tell you whether your script or your base changed.
Find the VM's IP address
Start the VM, select it in the library and open Connect in the inspector.
- IP Address shows "Waiting for an address…" until the VM has one. Copy IP Address copies it.
- SSH User is remembered per VM and defaults to your Mac's user name. Set it to the account you made in Setup Assistant.
- The Open SSH menu offers Open in Terminal, Open in iTerm (if installed), Open in VS Code and Copy SSH Command.
In Terminal, hermitbox ip mac-base prints the same address. To get the command, open Settings ▸ Advanced ▸ Command line tool and click Install. The default location is ~/.local/bin and needs no password, but that folder must be in your PATH. VM names are case-insensitive and a unique prefix is enough.
Take the clean snapshot
A snapshot is your safety net. If you ever dirty the base by accident, you can roll back.
- Shut the VM down with Machine ▸ Shut Down (⌘.).
- Choose Machine ▸ Take Snapshot (⇧⌘S), or use the Snapshots tab in the inspector. In the snapshot's ⋯ menu, choose Rename… and call it
clean.
On an APFS disk a snapshot is instant and takes no space until the VM changes. On a non-APFS disk it is a full copy, and Hermitbox asks before making it.
Run each test as a disposable VM
- Select
mac-basewhile it is shut down. - Choose Machine ▸ Run Without Saving Changes (⌥⌘R), or Option-click the ▶ on its box. In Terminal,
hermitbox start mac-base --disposabledoes the same. - The window shows a Disposable badge and an amber border: "Changes are discarded when it stops."
- Wait until Connect shows an IP address and copy it.
- Run your script or playbook from your Mac (next section).
- Inspect the result in the VM window. When you are done, close the window and confirm Stop and Discard Changes? Everything that changed since the run started is thrown away.
Point Ansible or your script at the VM
Ansible accepts a single host as an inline inventory if you add a trailing comma. This script waits for SSH, then runs the playbook against the address you pass in:
#!/bin/bash
# usage: ./run-test.sh VM_IP
set -euo pipefail
IP="${1:?Usage: $0 VM_IP}"
VMUSER="admin"
SSH_OPTS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null)
# wait until sshd answers
until ssh "${SSH_OPTS[@]}" -o BatchMode=yes -o ConnectTimeout=3 "$VMUSER@$IP" true 2>/dev/null; do sleep 3; done
# caffeinate -i keeps the Mac from idle sleep while the playbook runs
ANSIBLE_HOST_KEY_CHECKING=False caffeinate -i \
ansible-playbook -i "$IP," -u "$VMUSER" main.yml --ask-become-passThe host-key options skip known-hosts checks. That is acceptable for a throwaway VM on your own Mac and nowhere else. Read the IP fresh each run instead of hard-coding it. To fill it in automatically, try ./run-test.sh "$(hermitbox ip mac-base)". If that prints nothing, copy the address from Connect.
For a plain shell script or dotfiles bootstrap, skip Ansible:
ssh admin@"$IP" 'bash -s' < setup.shThis streams setup.sh to a shell on the VM. For an interactive session, run hermitbox ssh admin@mac-base.
Get your repo and results in and out
Under Shared Folders in the inspector, click Add Folder… and pick your dotfiles or playbook folder. Tick Read only if the test shouldn't modify it. Folders appear in the guest under /Volumes/My Shared Files. A VM that started with no shared folders picks up new ones at its next start, so add them while mac-base is shut down.
A disposable run forgets everything on its own disk. To keep logs, write them to a writable shared folder. You can also capture the VM window with Take Screenshot (⌃⌘S), which needs Screen Recording permission for Hermitbox.
Pick how you reset
| Method | How it resets | Keeps the result? | Use it when |
|---|---|---|---|
| Run Without Saving Changes | Throwaway copy, discarded on stop | No | Every normal test run |
| Snapshot + Restore… | Rolls the VM back to clean | Optionally (restore can snapshot the current state first) | You want to inspect a failed run, then reset |
| Use as Template | Starting it makes a copy named "NAME 2" (in 1.0.0) | Yes, in the copy | You want a persistent copy per experiment |
| Clone (⌘D) | Instant APFS copy with a new MAC address | Yes | You want to try two approaches from the same state |
From Terminal, hermitbox snapshot restore mac-base clean rolls back. It always snapshots the current state first, so old states pile up until you remove them with hermitbox snapshot delete mac-base SNAPSHOT. Clone needs the VM shut down or suspended.
Test on more than one macOS version
Create one base VM per version with Choose a Version…. It lists the newest build for each major version from macOS 13.6 up and flags any version newer than your Mac supports. Two macOS VMs can run at once, so two versions can run in parallel. A third won't start until you shut one down. See why you can only run two macOS VMs.
Other ways to do this
We make Hermitbox, so weigh this section accordingly.
- UTM is free (as of November 2026). It has snapshots, disposable and headless modes, plus
utmctland AppleScript. Per our November 2026 review, on its Apple Virtualization backend, snapshots, clones and disposable runs need macOS 27. - VirtualBuddy is free and open source under BSD-2 (as of November 2026). It has Apple restore images, a custom IPSW URL or file, recovery-mode boot, save and restore state, and a guest app for clipboard, shared folders and appearance sync.
- Tart is another VM tool people use for Mac CI and playbook testing. We haven't verified its current features or pricing, so check its own site.
If you only need a fresh macOS VM now and then, a free app may be all you need. Hermitbox's disposable runs, snapshot timeline and CLI are built for resetting the same VM many times a day. It is part of MacSuite ($349 one time as of November 2026), and you can try it free for 7 days.
Checklist before you run the playbook
mac-basewas created on an Apple silicon Mac and finished Setup Assistant.- Remote Login is on in the VM.
- Your public key is in the VM's
~/.ssh/authorized_keys. - You decided whether the base has the Command Line Tools.
- A
cleansnapshot exists. - The VM is running as a Disposable run and Connect shows an IP address.
If nothing works
"Connection refused" or "Operation timed out"
The VM hasn't finished booting, or Remote Login is off. Check that Connect shows an IP instead of "Waiting for an address…". If it does, start mac-base normally, turn on Remote Login, shut it down and take the snapshot again.
"Remote host identification has changed"
Your Mac has a stored key for that IP from a different VM. Remove the old entry, using your VM's address:
ssh-keygen -R 192.168.64.5This deletes that address from ~/.ssh/known_hosts. For throwaway VMs you can also use the host-key options in the script above.
Ansible fails with missing Python or a Command Line Tools prompt
The VM has no Command Line Tools yet. Run xcode-select --install in the VM, or add it to a bootstrap step before Ansible.
hermitbox ip prints nothing or "No IP address yet."
The VM is still starting. Wait a few seconds and try again, or copy the address from Connect.
"Two macOS VMs Are Already Running"
The message reads "macOS allows only two macOS VMs at a time. Shut one down, then try again." The alert has only an OK button, so shut one down yourself. Linux VMs don't count.
The playbook stalls partway through
Your Mac may have gone to sleep, which pauses running VMs. The caffeinate -i in the script prevents idle sleep (closing the lid still sleeps the Mac). Leave the VM's When Idle setting at Do Nothing, its default, so Hermitbox doesn't pause the VM while you work in another window.
If it still fails, contact support and include:
Hermitbox 1.0.0 on macOS (your version), Apple silicon.
Guest: macOS (version) VM named mac-base, started with Run Without Saving Changes.
Problem: (exact error text or what you saw, and when).
Connect shows: (IP address or "Waiting for an address…").
Tried: Remote Login on, ssh-copy-id, restarting the VM, snapshot restore.Common questions
Can I run the same playbook against several fresh VMs at once?
Two macOS VMs can run at the same time, so two parallel runs are the ceiling. Each disposable run counts toward that limit.
Will my snapshot survive a disposable run?
Yes. A disposable run works on a throwaway copy, and snapshots are separate. Snapshots aren't available during the disposable run itself.
Does this work on an Intel Mac?
No. macOS VMs in Hermitbox need Apple silicon.
Where do I read more about resets and automation?
See Snapshots, clones, templates and throwaway runs and Automate Hermitbox. For the first install, How to create a macOS virtual machine goes into more detail.