by webcoyote
Run AI agents isolated in a macOS user account and sandbox-exec. Configured to run Claude Code, OpenAI Codex, Cursor Agent, Google Gemini.
# Add to your Claude Code skills
git clone https://github.com/webcoyote/sandvault/Users/Shared/sv-$USERsandbox-execsv uninstallxcodebuild or swift see Sandboxing xcodebuild and swift for details.-x option. See Sandboxing other apps for details.SandVault has limited access to your computer:
No comments yet. Be the first to share your thoughts!
- writable: /Users/Shared/sv-$USER -- only accessible by you & sandvault-$USER
- writable: /Users/sandvault-$USER -- sandvault's home directory
- readable: /usr, /bin, /etc, /opt -- system directories
- no access: /Users/* -- other user directories
- writable: /Volumes/Macintosh HD -- accessible as per file permissions
- no access: /Volumes/* -- cannot access mounted/remote/network drives
Install via Homebrew:
brew install sandvault
Install via git:
# Clone the repository
git clone https://github.com/webcoyote/sandvault
# Option 1: add the sandvault directory to your path
export PATH="$PATH:/path/to/where/you/cloned/sandvault"
# Option 2: add to your shell configuration for easy access
echo >> ~/.zshrc 'alias sv="/path/to/where/you/cloned/sandvault/sv"'
echo >> ~/.bashrc 'alias sv="/path/to/where/you/cloned/sandvault/sv"'
# Run Claude Code in the sandbox
# shortcut: sv cl
sv claude
# Run OpenAI Codex in the sandbox
# shortcut: sv co
sv codex
# Run OpenCode in the sandbox
# shortcut: sv o
sv opencode
# Run Google Gemini in the sandbox
# shortcut: sv g
sv gemini
# Run command shell in the sandbox
# shortcut: sv s
sv shell
The default mode for sandvault runs commands as a limited user (basically sudo -u sandbox-$USER COMMAND). Sandvault also configures the limited sandvault account so that you can run commands via SSH (basically ssh sandbox-$USER@$HOSTNAME), and everything works the same. Use the -s or --ssh option to use SSH mode with sv, or use tmux or screen for users so inclined.
# Run using impersonation
# sv COMMAND
sv gemini
# Run using ssh
# sv -s/--ssh COMMAND
sv --ssh gemini
# Run AI agent with optional arguments
# Usage:
# sv <agent> [PATH] [-- AGENT_ARGUMENTS]
# Example:
sv gemini -- --continue
# Run shell command in sandvault and exit
# Usage:
# sv shell [PATH] -- [SHELL_COMMAND]
# Example:
sv shell /Users -- pwd # output: /Users
# Send input via stdin
# Usage:
# <producer> | sv shell [PATH] [-- SHELL_COMMAND]
# Examples:
echo "pwd ; exit" | sv shell /Users # output: /Users
echo ABC | sv shell -- tr 'A-Z' 'a-z' # output: abc
cat PROMPT.md | sv gemini
# Clone local/remote Git repository into /Users/sandvault-$USER/repositories/<git-repository> and open there
# Usage:
# sv <agent|shell> --clone URL_OR_LOCAL_PATH [-- AGENT_OR_SHELL_ARGS]
# Examples:
sv codex --clone https://github.com/webcoyote/sandvault.git
sv codex -c ~/src/my-app
sv shell --clone https://github.com/webcoyote/sandvault.git
sv shell -c ../my-app
Use a full or relative path with a directory name for local clones.
For local Git repositories, sandvault also wires remotes:
- Your local Git repository gets/updates remote `sandvault` -> `/Users/sandvault-$USER/repositories/<git-repository>`
- This lets you run `git fetch sandvault` from the original local Git repository to pull commits made in the sandvault Git repository.
By default, SandVault installs AI tools via Homebrew on the host side. With --native-install (-N), tools are instead installed inside the sandbox using their own installers:
curl -fsSL https://claude.ai/install.sh | bashnpm install -g @openai/codexcurl -fsSL https://opencode.ai/install | bashnpm install -g @google/gemini-cliTools are installed on first run and reused on subsequent runs.
# Install and run Claude Code natively
sv --native-install claude
sv -N claude
# Works with all AI agents
sv -N codex
sv -N opencode
sv -N gemini
To make native install the default, set SANDVAULT_ARGS:
# Add to your shell profile (~/.zshrc, ~/.bashrc, etc.)
export SANDVAULT_ARGS="--native-install"
# Now 'sv claude' uses native install automatically
sv claude
Set SANDVAULT_ARGS to supply default arguments that are prepended to the command line:
# Add to your shell profile (~/.zshrc, ~/.bashrc, etc.)
export SANDVAULT_ARGS="--verbose --ssh"
# Now these are equivalent:
sv claude
sv --verbose --ssh claude
Shell quoting is supported, so arguments with spaces work:
export SANDVAULT_ARGS='--clone "my project"'
Explicit command-line arguments are appended after SANDVAULT_ARGS, so they are processed afterwards.
# Build sandvault but do not run a command
sv build
sv b
# Rebuild sandvault, including updating all file permissions and ACLs in the shared volume
sv build --rebuild
sv b -r
# Fix permissions when using a restrictive umask (e.g. 077)
sv --fix-permissions
sv --fix-permissions build
# Uninstall sandvault (does not delete files in the shared volume)
sv uninstall
# Misc commands
sv --version
sv --help
In addition to running in a different macOS user account, sandvault also runs applications using macOS sandbox-exec, which further limits what resources are accessible.
Some applications, like swift, already run inside a sandbox. Because macOS does not support nested (i.e. recursive) sandboxes, these applications fail to run.
Read on for solutions.
For swift (and xcodebuild, which runs swift), you can set the following variables in your build scripts to run inside sandvault:
For swift:
ARGS=()
# Disable sandboxing when running inside sandvault to avoid nested sandbox-exec
if [[ -n "${SV_SESSION_ID:-}" ]]; then
ARGS+=(--disable-sandbox)
fi
swift build "${ARGS[@]}" "$@"
For xcodebuild:
ARGS=()
# Disable sandboxing when running inside sandvault to avoid nested sandbox-exec
if [[ -n "${SV_SESSION_ID:-}" ]]; then
export SWIFTPM_DISABLE_SANDBOX=1
export SWIFT_BUILD_USE_SANDBOX=0
ARGS+=("-IDEPackageSupportDisableManifestSandbox=1")
ARGS+=("-IDEPackageSupportDisablePackageSandbox=1")
# shellcheck disable=SC2016 # Expressions don't expand in single quotes # that is intentional
ARGS+=('OTHER_SWIFT_FLAGS=$(inherited) -disable-sandbox')
fi
xcodebuild \
build \
"${ARGS[@]}" \
...
If the app you intend to run does not support disabling the use of sandbox-exec like xcodebuild and swift you can run sandvault without sandbox-exec:
# Disable use of sandbox-exec (app still runs as sandvault user) using -x / --no-sandbox
sv -x claude
sv --no-sandbox codex
sv --no-sandbox shell $HOME/projects/my-app -- xcodebuild ...
Disabling sandbox-exec has the following security implications:
/Volumes/...)o+w (0002) file permissions# To find all files on your computer that are "world writable" (perms: `o+w` / 0002)
# run this command from your account (not in sandvault):
find / \
-path "/Users/sandvault-$USER" -prune \
-o -path "/Users/sv-$USER" -prune \
-o -perm -o=w -print 2>/dev/null
If your sandbox is misbehaving you can fix it with a rebuild or uninstall/reinstall. They're both safe and will not delete files in the shared sandbox folder.
# Force rebuild
sv --rebuild build
# Uninstall then reinstall
sv uninstall
sv build

If you see a security popup above, it may be because files in the shared sandvault directory don't have the correct ACLs, which occurs when another user's files are copied into the sandvault shared directory (/Users/Shared/sv-$USER). This can be corrected by running the rebuild command sv --rebuild build, or adding the rebuild flag to any command, e.g. sv -r shell. This only needs to be done once.