Skip to main content

Gemini CLI Sandboxing

How It Works​

When mcp-exec detects it is running under Gemini CLI (MCP_EXEC_RUNTIME=gemini), it skips SRT initialization entirely. Gemini provides its own opt-in native sandbox that wraps the entire agent process — including all MCP server subprocesses.

┌────────────────────────────────────────────────────────────────┐
│ Gemini native sandbox (when GEMINI_SANDBOX is enabled) │
│ (macOS Seatbelt / Linux bwrap|gVisor / Docker|Podman) │
│ Configured by: GEMINI_SANDBOX env var or tools.sandbox │
│ in ~/.gemini/settings.json │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ mcp-exec process │ │
│ │ SRT: not initialized │ │
│ │ │ │
│ │ ┌───────────────────────────────────────────────────┐ │ │
│ │ │ exec() code │ │ │
│ │ │ (Node: inside vm.Context) │ │ │
│ │ │ (Bash/Python: subprocess with filtered env) │ │ │
│ │ └───────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────┘
Gemini's sandbox is opt-in

Unlike Codex CLI, Gemini's sandbox is not enabled by default. If you run mcp-exec under Gemini without enabling the sandbox, SRT is still skipped and no OS-level isolation is active. Always set GEMINI_SANDBOX or tools.sandbox in your settings when using mcp-exec for untrusted workflows.

mcp-exec still applies application-level filters inside exec() — env var filtering (DEFAULT_ENV_ALLOW) and vm.Context isolation for Node — but these are not a substitute for OS-level sandboxing.

Platform Sandbox Mechanisms​

Gemini selects a sandbox mechanism based on the value of GEMINI_SANDBOX and the available tools on the host:

ValueMechanismPlatformNotes
true (auto)Platform defaultAllmacOS → Seatbelt; Linux → bwrap if available, else Docker
sandbox-execmacOS SeatbeltmacOSBuilt-in, no dependencies
bwrapbubblewrapLinux / WSL2sudo apt install bubblewrap
runscgVisor (strongest)LinuxUser-space kernel isolation; install separately
dockerDocker containerAllDocker daemon required
podmanPodman containerAllRootless alternative to Docker
lxcLXC/LXDLinuxFull-system containers; experimental

Detection: MCP_EXEC_RUNTIME=gemini​

mcp-exec detects the Gemini runtime via the MCP_EXEC_RUNTIME environment variable set in the extension manifest. At startup it also checks whether Gemini's sandbox is actually active:

  1. GEMINI_SANDBOX env var — set by the shell or inherited from the Gemini process
  2. tools.sandbox boolean in .gemini/settings.json or ~/.gemini/settings.json

Startup log when sandbox is active:

[mcp-exec] Gemini native sandbox active (bwrap) — SRT initialization skipped

Startup log when sandbox is not active:

[mcp-exec] Gemini runtime detected, no sandbox active — SRT skipped; enable GEMINI_SANDBOX for isolation

Configuration​

Enable Gemini's sandbox​

Via environment variable (recommended for CI/scripts):

export GEMINI_SANDBOX=true # auto-select
export GEMINI_SANDBOX=bwrap # Linux: bubblewrap
export GEMINI_SANDBOX=sandbox-exec # macOS: Seatbelt
export GEMINI_SANDBOX=docker # all platforms

Via settings file (recommended for day-to-day use):

~/.gemini/settings.json
{
"tools": {
"sandbox": true
}
}

Via CLI flag:

gemini -s # or --sandbox

Advanced sandbox options​

# Custom Docker image
export GEMINI_SANDBOX_IMAGE=my-custom-sandbox:latest

# Additional docker/podman flags
export SANDBOX_FLAGS="--memory=512m --cpus=1"

# Mount external directories
export SANDBOX_MOUNTS="/data:/data:ro,/tmp/output:/output:rw"

# macOS: override Seatbelt profile
export SEATBELT_PROFILE=restrictive-proxied

MCP server configuration (manual registration)​

If you are not using the extension manifest, add mcp-exec to your Gemini settings manually:

~/.gemini/settings.json
{
"mcpServers": {
"mcp-exec": {
"command": "npx",
"args": ["@joeblackwaslike2/mcp-exec"],
"env": {
"MCP_EXEC_RUNTIME": "gemini"
}
}
}
}

Or use the CLI helper:

gemini mcp add mcp-exec npx @joeblackwaslike2/mcp-exec
# then manually add env.MCP_EXEC_RUNTIME = "gemini" to the generated entry

Running Under Claude Code vs Codex vs Gemini​

ScenarioEnv varSRT initializedSandbox enforced by
Claude Code(absent)YesSRT + ~/.claude/settings.json
OpenCodeMCP_EXEC_RUNTIME=opencodeYesSRT + ~/.srt-settings.json
Codex CLIMCP_EXEC_RUNTIME=codexNoCodex platform sandbox (always active)
Gemini CLI (sandbox on)MCP_EXEC_RUNTIME=geminiNoGemini native sandbox
Gemini CLI (sandbox off)MCP_EXEC_RUNTIME=geminiNoNone — enable GEMINI_SANDBOX
Tests / CISKIP_SANDBOX=1NoNone

Skills​

The Gemini extension registers two skills automatically via GEMINI.md:

  • using-mcp-exec — activated when the model is about to call 2+ MCP tools in sequence or a single tool returning large results
  • mcp-exec-dev-workflow — activated during development research (fetching API docs, processing large responses)

The extension's contextFileName (GEMINI.md) is loaded as always-on context. Skills in the skills/ directory are loaded on-demand when the model identifies a matching task.

Troubleshooting​

Linux: bwrap not found​

sudo apt-get install bubblewrap # Ubuntu/Debian
sudo dnf install bubblewrap # Fedora
cat /proc/sys/kernel/unprivileged_userns_clone # must be 1
echo 1 | sudo tee /proc/sys/kernel/unprivileged_userns_clone

macOS: sandbox-exec permission denied​

On newer macOS, Seatbelt profiles may require additional entitlements. Switch to Docker if you encounter persistent permission errors:

export GEMINI_SANDBOX=docker

Startup log shows "no sandbox active" warning​

mcp-exec did not find GEMINI_SANDBOX in the environment or tools.sandbox: true in any settings file. Enable the sandbox via one of the methods above.

exec() code that was working stops working under the sandbox​

Gemini's sandbox restricts filesystem and network access. If exec() calls fail inside the sandbox that worked outside it:

  1. Check if the failure is filesystem or network with a minimal test
  2. For Docker/Podman: add mounts via SANDBOX_MOUNTS to expose required paths
  3. For bwrap: verify the working directory is within the allowed bind-mount set
  4. For Seatbelt: try SEATBELT_PROFILE=permissive-open to diagnose, then tighten