{"slug": "sandbox-claude-code-or-codex-on-a-mac-vm-container-lima-or-seatbelt", "title": "Sandbox Claude Code or Codex on a Mac: VM, container, Lima or Seatbelt", "summary": "A MacVisor comparison of ways to sandbox Claude Code, Codex CLI and Gemini CLI on a Mac finds that macOS's built-in Seatbelt sandbox, used via Claude Code's /sandbox, still allows reading credential files such as ~/.ssh and inherits environment variables including secrets, according to Anthropic's sandboxing documentation. The post notes Anthropic's docs state there is \"no built-in credential deny list\" and that only shell commands are sandboxed, while file tools, hooks and MCP servers run on the host; in bypass-permissions mode a host outside the allow list is permitted without a prompt unless strictAllowlist is set. The comparison covers Seatbelt, Apple's container, Lima and Colima, Docker and a full VM, and argues unattended agents need default-deny network egress, isolation from the local network, and enforcement outside the guest.", "body_md": "Claude Code, Codex CLI and Gemini CLI are most useful with their permission prompts off. On a Mac that means they run commands as you, next to your SSH keys, your cloud credentials and every other project you have. The vendors say to run them somewhere they can't do much harm, and leave the where to you.\n\nThis post compares the options on a Mac today: macOS's own sandbox (Seatbelt), Apple's `container`, Lima and Colima, Docker, and a full VM. We make [MacVisor](https://scaleninja.com/macvisor/), the last option, so read that section with that in mind.\n\n## What you're protecting\n\n- **Files:** your other projects,`~/.ssh` ,`~/.aws` .\n- **Keys:** API keys in variables or`.env` files, your SSH agent, git credentials.\n- **The network:** what the agent can read, it can send anywhere it can reach, including your LAN.\n- **Things that run later:** a changed git hook, CI file,`package.json` script or agent settings file runs on your Mac after the session.\n\nOur [step-by-step guide](https://scaleninja.com/blog/claude-code-full-auto-sandbox/) covers the risks in more detail.\n\n## Why network controls aren't optional\n\nA sandbox decides what an agent can read. The network decides whether any of it leaves. With prompts off, an agent reads READMEs, issues, web pages and package code that other people wrote, and any of them can carry instructions. Anthropic's [own docs](https://code.claude.com/docs/en/sandbox-environments) put it plainly: \"any approach that allows network egress can still leak data the agent can read\". So for an unattended agent, three network controls are part of the boundary, not extras:\n\n1. **Deny by default, then allow what the task needs:** the model's API and the package registries the project uses. An agent that can reach any host can send your code, its key or its environment to any host.\n2. **Keep it off your local network and your Mac.** A VM or container on ordinary NAT can reach what your Mac can: the router's admin page, a NAS, printers, other VMs, and services on the Mac itself, such as a dev database or a model server listening on every interface. An allow list written for the internet doesn't cover those unless it says so, and your LAN is where the things without passwords tend to live.\n3. **Enforce it outside the guest.** Rules inside the sandbox, such as iptables in a container, are only as strong as the agent's lack of root there, and an agent that installs packages often has it. A proxy or packet filter on the host is out of its reach.\n\nTwo more matter once you run several agents. Keep them apart, because traffic between machines on the same network often isn't filtered at all. And if your filter covers only IPv4, close IPv6, or it's a second way out.\n\nMost of the options below do one or two of these. The [side-by-side table](#side-by-side) shows which.\n\n## 1. macOS's own sandbox (Seatbelt)\n\nClaude Code, Codex and Gemini CLI can each wrap their commands in Seatbelt, the sandbox built into macOS. Nothing to install and no VM. The boundary is a policy on a process: same kernel, same user account, same disk.\n\n**Claude Code's `/sandbox`.** According to [Anthropic's sandboxing docs](https://code.claude.com/docs/en/sandboxing), Bash commands can write only to the working directory, a temp directory and folders you add. Reads are allowed across the whole computer by default, and the docs say plainly that this \"still allows reading credential files\" such as `~/.ssh`. Environment variables, secrets included, are inherited. Network traffic goes through a proxy with an allow list that starts empty. You can deny or mask specific files and variables, but \"there is no built-in credential deny list\".\n\nTwo catches matter for unattended runs. Only shell commands are sandboxed: file tools, hooks and MCP servers run on the host. And in bypass-permissions mode, which `--dangerously-skip-permissions` turns on, a host outside the allow list is allowed without a prompt, unless you set `strictAllowlist`. Anthropic's [sandbox environments page](https://code.claude.com/docs/en/sandbox-environments) says the Bash sandbox alone \"is not sufficient for fully unattended runs\", and recommends a container, a VM or its [sandbox runtime](https://github.com/anthropics/sandbox-runtime) (`srt claude`, a beta that puts the whole Claude Code process inside Seatbelt).\n\n**Codex.** Its [sandboxing docs](https://developers.openai.com/codex/sandboxing) describe three modes. The default, `workspace-write`, lets Codex edit inside the project and keeps `.git`, `.codex` and `.agents` read-only, and [network access is off](https://developers.openai.com/codex/agent-approvals-security) unless you turn it on. `--dangerously-bypass-approvals-and-sandbox` (also `--yolo`) removes the sandbox entirely, so \"no prompts\" and \"sandboxed\" don't go together here.\n\n**Gemini CLI.** Sandboxing is opt-in with `--sandbox`. The [default macOS profile](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/sandbox.md), `permissive-open`, confines writes to the project but allows broad reads and network access; stricter profiles exist.\n\nApple's man page marks `sandbox-exec`, Seatbelt's command-line front end, as deprecated, though it still works on macOS 27.\n\n**Good for:** fewer prompts during work you're watching. **Not for:** walking away with prompts off.\n\n## 2. Apple's `container`\n\nApple's [container](https://github.com/apple/container) tool runs each Linux container in its own lightweight VM. It's free (Apache 2.0), needs an Apple Silicon Mac with macOS 26 or later, and is at [1.7.1](https://github.com/apple/container/releases), released on 6 November 2026.\n\n```\ncontainer system start\ncontainer run -it --rm --volume \"$PWD:/work\" ubuntu:latest bash\n```\n\nThe boundary is good: a separate Linux kernel per container, and it sees only what you [mount](https://github.com/apple/container/blob/main/docs/volumes.md) (read-write unless you add `:ro`) and the variables you pass. Your SSH agent goes in only if you ask with [`--ssh`](https://github.com/apple/container/blob/main/docs/host-integration.md).\n\nIt has nothing made for agents, though. Your API key goes in, where the agent can read it. The [networking docs](https://github.com/apple/container/blob/main/docs/networking.md) cover isolated networks between containers but no egress filter or allow list, so a container reaches whatever the Mac's network does, LAN included, unless you filter it yourself. Changes come back through the mount, live, with no review step.\n\n**Good for:** a quick, clean Linux box with only the project in it, if you'll handle keys and network yourself.\n\n## 3. Lima and Colima\n\n[Lima](https://lima-vm.io/) runs Linux VMs from YAML templates and is free and open source; [2.3.0](https://github.com/lima-vm/lima/releases/tag/v2.3.0) came out on 6 November 2026. It has a page for [AI agents](https://lima-vm.io/docs/examples/ai/).\n\nMind the default first: Lima's [default template](https://github.com/lima-vm/lima/blob/master/templates/default.yaml) mounts your home folder read-only, so an agent in it can read `~/.ssh`. The AI page recommends mounting only the project (` limactl start --mount-only .:w`), or better, no mounts and its sync mode:\n\n```\nlimactl start --mount-none template:default\nlimactl shell --sync . default claude \"Add error handling to all functions\"\n```\n\n`--sync` copies the project in with rsync, runs the agent, then asks whether to accept the changes, with an option to view the diff. Use 2.3.0 or later: earlier versions had a [low-severity flaw](https://github.com/lima-vm/lima/security/advisories/GHSA-4wvf-9pjc-cpfp) where the guest could change files after you approved the diff, enough to plant a git hook. Lima also has an experimental [MCP server](https://lima-vm.io/docs/config/ai/outside/) and experimental [macOS guests](https://lima-vm.io/docs/usage/guests/macos/).\n\nThe gaps: API keys go into the VM (as variables or a sign-in), and the AI page describes no network restrictions.\n\n[Colima](https://github.com/abiosoft/colima) builds on Lima to run Docker. Its [default config](https://github.com/abiosoft/colima/blob/main/embedded/defaults/colima.yaml) mounts `$HOME` writable, which is convenient for containers and the opposite of what you want for an agent. If you use it, change the mounts first.\n\n## 4. Docker: dev containers and Docker Sandboxes\n\n**Dev containers.** Anthropic publishes a [reference dev container](https://code.claude.com/docs/en/devcontainer) with a default-deny iptables firewall inside the container that allows only the hosts Claude Code needs, and says it supports `--dangerously-skip-permissions`. The config lives in the repository, which suits teams. Its own warning: a malicious project can still take \"anything accessible inside the container, including the Claude Code credentials\". The project is bind-mounted, so edits land on your Mac as they happen. Docker Desktop is free only for personal use, education and [small businesses](https://docs.docker.com/subscription/desktop-license/) (under 250 employees and $10 million revenue).\n\n**Docker Sandboxes.** Docker's [sbx](https://docs.docker.com/ai/sandboxes/) is built for exactly this job, and it's strong. Each sandbox is a microVM with its own kernel and Docker daemon, and it doesn't need Docker Desktop. Per its [security page](https://docs.docker.com/ai/sandboxes/security/), a proxy on the host adds your credentials to outgoing requests and \"the raw credential values never enter the VM\", and outbound traffic goes through the host under a deny-by-default policy. Sandboxes can't reach each other or your host network directly. The CLI and local sandboxes are free, including for commercial work, and it [installs](https://docs.docker.com/ai/sandboxes/install/) with Homebrew on macOS 14 or later on Apple Silicon. It supports Claude Code, Codex, Copilot, OpenCode and [others](https://docs.docker.com/ai/sandboxes/agents/).\n\n```\nsbx run --clone claude .\n```\n\nTwo defaults to change. The [default mode](https://docs.docker.com/ai/sandboxes/usage/) mounts your working tree read-write, so changes appear on your Mac at once; `--clone` gives the agent its own git clone and you fetch what you want. And the default allow list is broad (it includes `*.googleapis.com`), so prune it with `sbx policy ls`. You also need a Docker sign-in, and the guests are Linux.\n\n## 5. A full VM: a MacVisor AI sandbox\n\n[MacVisor](https://scaleninja.com/macvisor/) runs full VMs on Apple Silicon Macs with macOS 27. An [AI sandbox](https://scaleninja.com/macvisor/ai-sandboxes/) is a VM set up for one agent:\n\n```\nmvz ai keys set anthropic\nmvz sandbox create ~/src/app --agent claude\nmvz sandbox run app-1 -- \"fix the failing parser test\"\nmvz sandbox diff app-1 --patch\nmvz sandbox apply app-1\n```\n\n- **Boundary:** a whole VM, Linux (Ubuntu 26.04, 2 CPUs and 4 GiB by default) or macOS 27 for Xcode work.\n- **Files:** a copy of the working tree, without git history or ignored files. No shared folders, clipboard or USB, and MacVisor connects without forwarding your SSH agent.\n- **Keys:** stay in the Mac's Keychain. A gateway on the Mac adds them to model requests on the way out, for Anthropic, OpenAI and OpenRouter, or the agent uses a local model.\n- **Network:** an allow list enforced outside the VM, with presets such as`npm` and`pypi` . The VM sits on a host-only network,**MacVisor Sandboxes** , whose firewall in the Mac's packet filter denies traffic in and out. So it reaches the models and the listed sites through MacVisor and nothing else: not your LAN, and not your Mac, unless an entry names one exactly.`mvz sandbox create` won't make a sandbox while that firewall isn't in force. The gateway also refuses provider-side tools like web fetch that could reach sites around the list.\n- **Changes:** a diff made on your Mac with your git. Scripts, hooks, CI files and agent settings are flagged, and`apply` brings in exactly what you reviewed, or onto a new branch.\n- **Undo:** a`pristine` checkpoint of the whole VM, running processes included.\n\nAgents set up for you are Claude Code, Codex, Goose, Aider and OpenCode. Gemini CLI isn't one; with `--agent none` you'd install it yourself and its key would live in the VM.\n\n### Agents that need the open internet\n\nSome agents don't fit an allow list: one signed in with a Claude or ChatGPT subscription, or one that runs all the time and browses, like [OpenClaw](https://scaleninja.com/macvisor/openclaw/). Give each a VM on a custom network of its own, with a firewall that allows the internet and denies the private address ranges, so it can't reach your router, NAS or the Mac:\n\n```\nmvz networks create agents\nmvz networks firewall agents on --inbound deny --outbound allow \\\n  --deny out:any::10.0.0.0/8 --deny out:any::172.16.0.0/12 --deny out:any::192.168.0.0/16\nmvz create ubuntu agent-1 --network agents\n```\n\nThe [firewall](https://scaleninja.com/docs/macvisor/firewall/) lives in the Mac's packet filter, so nothing in the VM can turn it off, and the Mac drops IPv6 on that network so the guest can't go around it. Traffic between VMs on one network isn't filtered, so give agents you need kept apart a network each.\n\nOn an office network, go one step further with a [VLAN interface](https://scaleninja.com/docs/macvisor/custom-networks/#vlan-interfaces) (**Networks → New VLAN Interface…**). Use it as the custom network's uplink, and the agent's traffic leaves the Mac tagged onto a segment your router and switches already keep away from staff machines, with MacVisor's firewall in front. When other devices must reach the agent, bridge its VM to the VLAN interface instead, and let that segment's rules do the filtering: MacVisor's firewall applies to custom networks, not bridged adapters.\n\nThe weaknesses are real. It's the heaviest option, with gigabytes of memory per sandbox and about a minute to make one. Your editor doesn't see changes until you apply them. A Claude or ChatGPT subscription sign-in needs open internet for that sandbox, so use a firewalled network as above. A Mac runs at most two macOS VMs. Sandboxes on the allow-list network can reach each other, which Docker's can't, and an allowed site on a shared CDN can open the way to others on it. AI sandboxes are a Tech Preview, and MacVisor is paid after a 30-day free trial, with a [one-time Pro license](https://scaleninja.com/macvisor/#pricing).\n\n## Side by side\n\n|  | Boundary | Agent can read | API keys | Network | Changes come back | Cost | \n|---|---|---|---|---|---|---|\n| Claude Code `/sandbox` | Process policy, your account | Whole disk by default | In its environment | Allow list in a proxy on the Mac; bypass mode allows new hosts unless strict | Live, in your tree | Free | \n| Codex `workspace-write` | Process policy, your account | Not limited in the docs | In its environment | Off by default | Live, in your tree | Free | \n| Apple `container` | Lightweight VM per container | What you mount | Inside | No egress filter | Live, through the mount | Free | \n| Lima `--sync` | Linux VM | A copy of the project | Inside | No limits described | Prompt with a diff | Free | \n| Dev container | Container in Docker's VM | The mounted project | Inside | Default-deny firewall inside the container | Live, through the mount | Docker Desktop terms | \n| Docker Sandboxes | microVM | Project (mount or clone) | Injected by host proxy | Deny by default through the host, broad list | Live, or git fetch | Free locally | \n| MacVisor AI sandbox | Full VM, Linux or macOS | A copy of the project | Injected by Mac gateway | Allow list on the Mac, firewalled host-only network | Reviewed diff, then apply | One-time license | \n\n## Which to pick\n\n- **You watch the agent and want fewer prompts:** the agent's own sandbox, Claude Code's`/sandbox` or Codex's`workspace-write` . Nothing to set up. Don't treat it as the boundary for`--dangerously-skip-permissions` .\n- **A Linux project and you want it free:** Docker Sandboxes, with`--clone` and a trimmed allow list. It keeps keys out of the VM, which most free options don't.\n- **You already live in Lima, or want everything open source:** Lima 2.3 or later with`--mount-none` and`--sync` . Accept that keys sit in the VM, and use a low-limit key.\n- **A team that wants the same setup everywhere:** Anthropic's reference dev container, committed to the repo.\n- **Just a clean, throwaway Linux shell:** Apple's`container` , mounting only the project.\n- **An agent that needs the open internet or runs all the time:** a VM on a firewalled network of its own, or behind a VLAN, as[above](#agents-that-need-the-open-internet) . Not just another machine on your LAN.\n- **You need macOS or Xcode in the sandbox, want keys never in the guest, an allow list the agent can't touch, or a reviewed diff as the only way back:** a full VM. That's what we built[MacVisor's AI sandboxes](https://scaleninja.com/macvisor/ai-sandboxes/) for, and the[how-to](https://scaleninja.com/blog/claude-code-full-auto-sandbox/) has the steps.\n\nLayering is fine too. Anthropic's docs suggest running the Bash sandbox inside a container or VM for a second boundary.\n\n## Common questions\n\n### Is `--dangerously-skip-permissions` safe with Claude Code's sandbox on?\n\nNot on its own, per [Anthropic](https://code.claude.com/docs/en/sandbox-environments). Hooks, MCP servers and file tools run outside it, and in that mode new hosts are allowed without asking. Use a container, a VM or the sandbox runtime.\n\n### Can the agent push with my SSH key or git credentials?\n\nOn the Mac, yes, unless you deny those files. In a container or VM, only if you mount `~/.ssh`, forward your SSH agent or hand it a token. Keep pushes on the Mac, after you review.\n\n### Can the agent read my Mac's Keychain?\n\nNot from a Linux container or VM: it isn't there. In a macOS VM, it gets the VM's own Keychain, not yours.\n\n### Can an agent in a VM or container reach my home or office network?\n\nUsually, yes. On ordinary NAT it reaches what your Mac reaches, LAN included. Docker Sandboxes send outbound traffic through a deny-by-default proxy, and MacVisor's allow-list sandboxes reach your LAN only through an entry that names a device exactly. For anything else, put the agent on a network with a firewall outside the guest that denies the private address ranges.\n\n### Does a sandbox stop prompt injection?\n\nNo. It limits what an injected instruction can read, where it can send it, and what lands in your code.\n\nMore on MacVisor's approach: [AI sandboxes](https://scaleninja.com/docs/macvisor/ai-sandboxes/), [AI agents and MCP](https://scaleninja.com/docs/macvisor/ai-agents/), and [MacVisor vs. Lima](https://scaleninja.com/macvisor/vs/lima/).", "url": "https://wpnews.pro/news/sandbox-claude-code-or-codex-on-a-mac-vm-container-lima-or-seatbelt", "canonical_source": "https://scaleninja.com/blog/sandbox-ai-coding-agents-mac/", "published_at": "2026-11-26 00:00:00+00:00", "updated_at": "2026-11-26 07:44:40.503601+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety"], "entities": ["Claude Code", "Codex CLI", "Gemini CLI", "Anthropic", "Apple", "MacVisor", "Lima", "Colima"], "also_reported_by": [], "takeaway": "Claude Code's /sandbox Seatbelt mode restricts Bash writes to the working directory but still reads credential files like ~/.ssh and inherits secrets in environment variables, so unattended runs need a host-level egress proxy with a default-deny allow list and strictAllowlist set.", "recommendation": {"advice": "Run unattended coding agents behind a host-level proxy with default-deny egress and strictAllowlist enabled, since Claude Code's Seatbelt sandbox still reads ~/.ssh and inherits secrets.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/sandbox-claude-code-or-codex-on-a-mac-vm-container-lima-or-seatbelt", "markdown": "https://wpnews.pro/news/sandbox-claude-code-or-codex-on-a-mac-vm-container-lima-or-seatbelt.md", "text": "https://wpnews.pro/news/sandbox-claude-code-or-codex-on-a-mac-vm-container-lima-or-seatbelt.txt", "jsonld": "https://wpnews.pro/news/sandbox-claude-code-or-codex-on-a-mac-vm-container-lima-or-seatbelt.jsonld"}}