Just a show-and-tell, basically, not a full-fledged project.
This is my personal take on sandboxing Claude Code and similar AI agents.
I want…
- to run LLM agents inside clearly defined boundaries on macOS to restrict file write access.
- a sandbox to put them in, one they can't break.
- read-write access to the current folder, and configurable optional read-only access to others.
- the agents to be able to build Xcode projects (because that's what I do), which is usually not as easy, lest you set up a full macOS VM with a full Xcode setup inside, and … nope.
Also, I want that thing to boot up in less than 5s.
I've settled on two different approaches, and work with them
| Approach | Isolation | Startup | Best For |
|---|---|---|---|
| claude-containered | Docker via OrbStack | ~1-2s | Stronger isolation, containerized tools, bit more involved to get git credentials going etc. |
| claude-sandboxed | macOS sandbox-exec | Instant | Lightweight, native performance |
Both approaches share the same idea:
- MCP servers run on the host (outside the sandbox) via supergateway
- Claude runs inside the sandbox with restricted write access
- Claude connects to MCP servers via HTTP/SSE
This lets tools like xcsift-mcp invoke xcodebuild freely—no nested sandbox issues. (Side note: Big Swift dev shoutout to xcsift!)
I'm scratching my own itch here—restricting file write access so agents can only modify the current project and a few config directories. None of this is rocket science, but I was learning a few things, and sharing is caring.
This is an opinionated setup! I love fish shell, I dig gum. The upside is that the scripts are documented and rather easy to read and translate.
No guarantees, no claims of bulletproof security. I might be wrong about some of this. Use at your own risk. Feel free to mix and match!
# OrbStack version (builds image on first run)
./claude-containered/claude-containered
# Native `sandbox-exec`-based version (macOS only)
./claude-sandboxed/claude-sandboxedBoth use the same config format. Create .claude/cc-sandbox-host.mcp.json in your project:
./claude-containered/claude-containered --init-mcp
# or
./claude-sandboxed/claude-sandboxed --init-mcpSee the individual READMEs for details.
claude-containered:
- OrbStack
jq,gum
claude-sandboxed:
- macOS
jq,gum,nc
Both require npx and supergateway if using MCP servers.