Run Claude Code in a macOS VM Sandbox (Codex, OpenCode too)
Run Claude Code, Codex or OpenCode inside a macOS VM with only the project folder shared, then discard the agent's changes with a disposable run or snapshot.
GuideUpdated 8 min read
On this page
You want Claude Code, Codex or OpenCode to run commands freely, but not on the Mac that holds your files, keys and browser sessions. Docker doesn't solve this for macOS work, so a macOS virtual machine on Apple silicon is the usual answer. We make Hermitbox, so weigh our view accordingly. As of November 2026 the published version is 1.0.0, and it includes shared folders, snapshots, "Run Without Saving Changes" and a hermitbox command-line tool. It has no agent-specific features, and we don't claim any agent behaves a particular way inside it.
Why a macOS VM and not Docker
Docker on a Mac runs Linux containers inside a Linux VM, so it can't give an agent a real macOS to build, test or script against. A macOS guest can. Apple's Virtualization framework boots and runs macOS or Linux-based operating systems in custom environments, and Hermitbox is built on it. If your project builds fine on Linux, a Linux VM is a lighter choice (see below).
The agent tools also have their own guardrails. Claude Code, for example, has an opt-in /sandbox command whose runtime runs on your machine and supports both file and network isolation, according to Anthropic's support article. A VM is a separate layer: it puts the whole operating system between the agent and your Mac. You can use both. Our guide on a safer alternative to --dangerously-skip-permissions covers the permission side.
What a VM sandbox protects, and what it doesn't
Protected: commands the agent runs happen in the guest, which has its own disk and sees only the folders you share.
Not protected:
- The shared folder is real. Anything the agent writes there stays on your Mac, even in a disposable run. Share a fresh checkout, never your home folder.
- Anything you type into the VM. API keys, tokens and git credentials entered in the guest are available to the agent. Use credentials you can revoke.
- The network. In 1.0.0 every VM uses Apple's NAT network. The VM reaches the internet, and there is no setting to cut it off. The agent needs its API anyway.
- The clipboard. Sharing is on by default for new macOS VMs once Hermitbox Guest is installed. Turn it off (Step 3).
What you need
- A Mac with Apple silicon. Hermitbox doesn't run macOS VMs on Intel Macs.
- macOS 14 Sonoma or later on the host. The guest can be macOS 13 or later.
- Disk and memory: a macOS VM needs at least 64 GB of disk and 4 GB of memory. Hermitbox recommends 4 cores, 8 GB and 80 GB, fitted to your Mac. The disk fills only as the VM uses it.
- Room under the two-VM limit: only two macOS VMs can run at once, and disposable runs count. See why you can only run two macOS VMs at once.
Step 1: Create the macOS VM
- Choose File ▸ New VM… (⌘N).
- On What would you like to run?, choose macOS.
- On Choose a Source, pick Latest macOS (marked "Recommended"), or Choose a Version… if the project needs an older release.
- On Name and Size, use a short name without spaces, such as
agent-box. It is easier to type on the command line. Keep the recommended sizes, then click Create. - Wait for the download and install (Hermitbox estimates about ten minutes). The VM boots into Setup Assistant.
- Finish Setup Assistant and create a user inside the VM.
The macOS VM docs page covers versions, downloads and failures.
Step 2: Share only the project folder
- On your Mac, make a fresh copy of the project, for example a
git clonein a folder you use only for agent work. - Select the VM in the library and open the inspector (⌃⌘I if hidden).
- Under Shared Folders, click Add Folder… and choose that folder, or drop a folder from Finder onto the list.
- Decide on Read only. Leave it unticked if the agent must write; tick it for review-only work. Change it later with Make Read Only or Allow Writing.
Inside a macOS guest, shared folders appear in /Volumes/My Shared Files. If Hermitbox Guest is installed, it also mounts them at ~/Hermitbox Shared when that folder is missing. A folder added to a VM that started with none applies at the next start.
Step 3: Turn off clipboard sharing
- In the VM's window, open the Sharing popover.
- Switch Clipboard off. The same switch is under VM Settings ▸ Sharing ▸ Share the clipboard.
Clipboard sharing on macOS guests needs Hermitbox Guest, so leaving Guest uninstalled also works.
Step 4: Install the tools and agent in the base VM
Start the VM and work inside it like a fresh Mac. For compilers and git, run this in the guest's Terminal. It opens Apple's installer for the Command Line Tools:
xcode-select --installThen install your agent. For Claude Code, follow how to install Claude Code on a Mac. For Codex and OpenCode, use each vendor's documentation.
Install everything now. A disposable run starts from the VM as it is at that moment, and anything installed or signed in during the run disappears afterward. If you plan to use SSH, turn on Remote Login in the guest's System Settings now too. When the base is ready, choose Shut Down (⌘.).
Step 5: Choose how changes get discarded
| Method | Start it with | What it undoes | Limits |
|---|---|---|---|
| Run Without Saving Changes | ⌥⌘R, or Option-click ▶ | All VM changes since start | No Suspend or Snapshot during the run |
| Snapshot, then restore | ⇧⌘S; Restore… later | VM changes since the snapshot | Full copy on non-APFS disks |
| Clone per task | ⌘D | Nothing; Trash the clone after | VM must be shut down or suspended |
None of these touch the shared folder on your Mac.
Option A: Run Without Saving Changes
- Select
agent-boxin the library. - Choose Machine ▸ Run Without Saving Changes (⌥⌘R), or Option-click ▶ on the box.
- Check for the Disposable badge and amber border.
- Sign in to the agent, run it on the shared folder, and review the results on your Mac.
- When you close the run, Hermitbox asks Stop and Discard Changes? Confirm, and everything that changed in the VM since it started is thrown away, including logins.
Option B: Snapshots
Use snapshots when you want tools and logins to persist but need a way back.
- Choose Machine ▸ Take Snapshot (⇧⌘S). A running VM is briefly suspended first, and the snapshot is marked "Includes running state".
- Run the agent.
- To go back, open the inspector's Snapshots tab, click ⋯ on the snapshot and choose Restore….
- Leave Snapshot the current state first ticked unless you're sure you won't want the current state back.
On APFS disks snapshots are instant and take no space until the VM changes. On other disks they are full copies and Hermitbox asks first. You can also tick Before each start with Keep N (1 to 20, default 3); this needs APFS.
Option C: One clone per task
Choose Machine ▸ Clone (⌘D) on a shut-down or suspended VM. You get "agent-box copy" with a new MAC address and no snapshots. Run the agent there, then choose Move to Trash… (⌘⌫).
Step 6: Review what the agent did
Check the real folder with git on the Mac side. Both commands only read:
git -C ~/agent-work/myproject status
git -C ~/agent-work/myproject diffReplace the path with your shared folder. The next command discards all uncommitted edits to tracked files and can't be undone:
git -C ~/agent-work/myproject restore .It doesn't remove new files the agent created. Delete those by hand, or delete the whole checkout.
Script it with the hermitbox command line
Install the tool from Hermitbox ▸ Settings ▸ Advanced ▸ Command line tool ▸ Install. The default location, ~/.local/bin, needs no password; make sure it's in your PATH.
hermitbox start agent-box --disposable
hermitbox snapshot create agent-box
hermitbox snapshot list agent-box
hermitbox snapshot restore agent-box SNAPSHOT
hermitbox suspend agent-box
hermitbox ip agent-box
hermitbox ssh agent-boxstart --disposablebegins a throwaway run and can't be combined with--headless.snapshot restoregoes back to the snapshot you name (replaceSNAPSHOT) and always snapshots the current state first.suspendsaves the VM's state and stops it.ipprints the VM's address.sshneeds Remote Login on in the guest.
Names are case-insensitive and a unique prefix works. The tool can't create VMs or change settings, so create agent-box in the app first. The automation docs list every command and exit code.
Checklist before you start an agent run
- The VM has its tools and agent installed, and was shut down cleanly.
- Only a fresh checkout is shared, not your home folder.
- Clipboard sharing is off, or Hermitbox Guest isn't installed.
- Credentials inside the VM are ones you can revoke.
- You started a disposable run or took a snapshot first.
- You have a plan to review the shared folder with
git diff.
If something doesn't work
- Folder missing in the guest. Look in
/Volumes/My Shared Files. If you added it after the VM started with none, shut down and start again. - Agent can't write. The folder is probably Read only. Choose Allow Writing.
- "Two macOS VMs Are Already Running". The message reads "macOS allows only two macOS VMs at a time. Shut one down, then try again." It has an OK button only.
- Suspend and Take Snapshot unavailable. They're off during disposable runs. Use Option B.
- Tools or login gone. You set them up during a disposable run. Install in the base VM instead.
hermitbox ipsays "No IP address yet." The VM may still be booting. Wait a few seconds.
If nothing works
Contact MacSuite through the support page. Include your Mac model and macOS version, the exact message shown, the steps you tried and whether the VM was a disposable run.
Subject: Hermitbox 1.0.0, shared folder / disposable run problem
Mac: (model, macOS version)
Guest: macOS (version)
What I did: created VM "agent-box", shared one folder, started with Run Without Saving Changes
What happened: (exact message or behavior)
Already tried: restarting the VM, re-adding the shared folderCommon questions
Can the agent escape the VM?
We can't promise that no VM escape exists, and we haven't tested any agent's behavior inside Hermitbox. The practical risks are the shared folder, credentials you enter, and the network.
Does this work for Codex and OpenCode?
Yes in principle: the VM is a normal macOS, so anything you can install on a Mac you can install in the guest. Hermitbox has no agent-specific features.
Can I run more than two of these VMs?
Not macOS ones. Apple's limit is two at a time, and it's possible to run up to 2 macOS virtual machines on a Mac. Use Linux VMs for extra parallel work.
Why not just use Docker?
Docker can't provide macOS. Use it when Linux is enough; use a macOS VM when the agent must work in a real macOS environment.
Try Hermitbox
Hermitbox is part of MacSuite, and you can try it free for 7 days (as of November 2026). See the Hermitbox page, or the snapshots, clones and throwaway runs docs.