Deepseek ArtifactsDeepseek Artifacts
Illustrated guide · updated for v0.61.0

Gemini CLI Sandbox Mode: Enable, Backends, YOLO Safety

The illustrated, no-fluff guide to sandboxing Gemini CLI: launch with -s, make it permanent, pick the right backend for your OS, and give YOLO mode a guardrail.

TL;DR

  • Run gemini -s and the whole session — shell commands, file edits, network calls — executes inside an isolated sandbox; a sandbox chip appears in the footer so you can see it is active.
  • Three ways to enable it, resolved in order of precedence: the -s / --sandbox flag, the GEMINI_SANDBOX environment variable, or "sandbox": true in the tools object of settings.json.
  • Backends are per-OS: macOS Seatbelt profiles (permissive-open by default), Linux gVisor runsc for the strongest isolation, Docker or Podman containers everywhere else.
  • YOLO mode (--yolo) skips every permission prompt — pair it with the sandbox. v0.61.0 (Sept 23, 2026) hardened the sandbox filesystem boundaries and isolated runtime state.

Gemini CLI Essentials – Full Course (sandboxing chapter)

Channel: freeCodeCamp.org3:49:40

Open on YouTube

Gemini CLI: Everything You Need To Know (Full Tutorial)

Channel: lustoykov42:54

Open on YouTube

Sandboxing in Gemini CLI — official documentation

Docs: google-gemini/gemini-cli (GitHub)

Open on YouTube

Frames come from the freeCodeCamp course's sandboxing chapter; flag names, settings and profiles were double-checked against the official sandbox documentation and the v0.61.0 release notes.

Screenshots credit: freeCodeCamp.org and lustoykov — recordings used as visual reference with attribution; all step text is ours.

Sandbox Gemini CLI, step by step

Launch your first sandboxed session

  1. 1

    Know what the sandbox actually protects

    Sandboxing isolates the operations that turn an AI agent dangerous — shell commands, file writes and network calls — from your host system. Gemini CLI v0.61.0 (September 23, 2026) hardened the sandbox filesystem boundaries and isolated runtime state, closing indirect prompt-injection routes through build files and untrusted flags.

    Course slide explaining that Gemini CLI sandboxing relies on OS-level sandboxing libraries — gVisor and runsc or LXC/LXD on Linux WSL2, Seatbelt on macOS, and Docker or Podman containers
    Where sandboxing sits: an OS-level isolation library picked per platform.Watch at 140:00
  2. 2

    Launch straight into a sandbox with the flag

    The quickest route is the command flag: run gemini -s (long form --sandbox). The first launch can take a minute because the sandbox image may need pulling. For one-shot runs, combine it with a prompt: gemini -s -p "analyze the code structure".

    Gemini CLI course slide showing the gemini --sandbox launch command next to a terminal footer where a sandbox version chip confirms the session is sandboxed
    Flag on, footer chip on — the two-second sanity check.Watch at 140:50
  3. 3

    Learn the three ways to enable it — and which one wins

    Gemini CLI resolves sandboxing in order of precedence: first the -s / --sandbox command flag, then the GEMINI_SANDBOX environment variable (true, docker, podman, sandbox-exec, runsc or lxc), then the "sandbox" entry in the tools object of your settings.json.

    Official Gemini CLI documentation Sandboxing section listing the three ways to enable the sandbox: the -s flag, the GEMINI_SANDBOX environment variable, or the sandbox setting in settings.json
    The official docs list all three enable routes in precedence order.Watch at 145:45
  4. 4

    Confirm the session is sandboxed in the footer

    Once the CLI is up, the status footer shows a sandbox chip with the sandbox component's version, right next to the model selector. No chip means no sandbox — go back and check which flag or setting you thought was enabling it.

    Gemini CLI session footer showing the sandbox version chip next to the Auto Gemini 3 model selector while the agent thinks inside the sandbox
    A live sandboxed session: the chip sits beside Auto (Gemini 3).Watch at 146:40

Pick the right backend for your OS

  1. 5

    On macOS, ride the built-in Seatbelt

    macOS needs no containers: Gemini CLI wraps the process with Seatbelt (sandbox-exec). The default profile, permissive-open, confines writes to the project directory while reads and network stay open. Harden it with the SEATBELT_PROFILE environment variable — permissive-proxied, restrictive-open, restrictive-proxied, strict-open or strict-proxied.

  2. 6

    On Linux or WSL2, meet gVisor runsc

    Google's gVisor — the runsc runtime — is the strongest isolation available: containers run against a user-space kernel that intercepts every system call. Select it explicitly with GEMINI_SANDBOX=runsc or "sandbox": "runsc" (it is never auto-detected) and Gemini CLI will launch docker run --runtime=runsc for you.

    Gemini CLI documentation page for the gVisor runsc sandbox backend, the strongest Linux-only isolation that runs containers inside a user-space kernel
    The docs position runsc as the strongest, Linux-only backend.Watch at 141:20
  3. 7

    Install the runsc runtime

    On Ubuntu — native or inside WSL2 — one apt command fetches the gVisor runtime: sudo apt get install runsc. You also need Docker installed and running, because Gemini CLI drives runsc as a Docker runtime rather than as a standalone tool.

    WSL2 Ubuntu terminal in VS Code running sudo apt get install runsc to set up the gVisor runtime for Gemini CLI sandbox mode
    Typing the install command in a WSL2 Ubuntu terminal.Watch at 143:35
  4. 8

    Check the install landed

    apt unpacks runsc straight from Ubuntu's security updates repository — no extra PPA. If you skip this step, a later gemini -s on Linux fails or silently falls back to the container backend, so verify the package is present before your first sandboxed run.

    apt output finishing the runsc package install on Ubuntu 24.04, the gVisor runtime that backs Gemini CLI sandbox containers on Linux
    apt finishes unpacking runsc on Ubuntu 24.04.Watch at 144:15
  5. 9

    Prefer containers? Docker or Podman on any OS

    Container-based sandboxing works anywhere Docker or Podman runs, and both must be installed and running before you start — run docker once to confirm the CLI answers. The sandbox uses the ghcr.io/google/gemini-cli:latest image by default and mounts your working directory at the exact same absolute path inside the container.

    Docker CLI global options printed in a VS Code terminal to confirm the Docker engine is installed and answering before enabling container-based Gemini CLI sandboxing
    Running docker once to confirm the engine answers.Watch at 145:30

Run YOLO mode without the sweat

  1. 10

    Pair the sandbox with YOLO mode

    gemini --yolo (short for --approval-mode=yolo) dangerously skips every permission prompt — exactly what autonomous runs need, and exactly what a sandbox is for. Launch YOLO sessions with the sandbox flag so the skipped prompts still land inside the isolated environment.

    Slide introducing Gemini CLI YOLO mode where the --yolo or --approval-mode=yolo flag dangerously skips every permission prompt
    YOLO mode in one slide: no interruptions, all permissions skipped.Watch at 148:20
  2. 11

    Verify autonomous runs stayed sandboxed

    During YOLO sessions the footer swaps in a blue YOLO Mode badge — your cue that prompts are being skipped. After the run, the /stats interaction summary shows which tools fired, and the sandbox chip stays your proof the work happened inside the box.

    Gemini CLI interaction summary in VS Code with the blue YOLO Mode badge glowing in the status footer after an autonomous session
    The YOLO Mode badge in the footer of a finished autonomous session.Watch at 147:40

Custom sandbox images and container flags

The default container image is fine for generic coding work. When your project needs its own toolchain — or your container setup fights you — Gemini CLI gives you four dials.

  • 1Point at any image: set GEMINI_SANDBOX_IMAGE, or use the object form in settings.json — "sandbox": "command": "docker", "image": "..." (a JSON object). Any Docker or Podman image that ships bash works.
  • 2Build your own: drop a .gemini/sandbox.Dockerfile in the project root and run with BUILD_SANDBOX=1 — Gemini CLI builds the image automatically. Automatic builds only work when running the CLI from source; npm installs should reference a prebuilt image.
  • 3Tune the container command: SANDBOX_FLAGS injects extra docker/podman flags — for example export SANDBOX_FLAGS="--security-opt label=disable" cures SELinux volume-mount denials on Podman.
  • 4Fix file ownership on Linux: the sandbox maps user permissions automatically, but SANDBOX_SET_UID_GID=true forces the host UID/GID when generated files come out owned by the wrong user.

Running Gemini CLI itself inside a container and want to sandbox within? Mount /var/run/docker.sock so the CLI can spawn sibling containers through the host daemon, and make the workspace path match the host's absolute path exactly — the host daemon resolves volume mounts, not the container.

Troubleshooting: errors, file access, disabling

Most sandbox trouble reduces to five patterns. Before anything else, reproduce with debug output: DEBUG=1 gemini -s -p "your prompt".

  • 1"Operation not permitted" — the command needs access outside the sandbox. Move to a more permissive profile (macOS: SEATBELT_PROFILE) or add the required mount points.
  • 2Missing commands inside the sandbox — bake your tools into a custom image, or install them via sandbox.bashrc. Remember BUILD_SANDBOX automation is for source checkouts only.
  • 3Network failures — check the active profile allows network at all, and verify proxy configuration; the -proxied profiles route traffic through the sandbox proxy.
  • 4Files created with the wrong owner on Linux — flip SANDBOX_SET_UID_GID (true forces the host UID/GID, false disables the mapping).
  • 5Windows left files marked Low integrity — the native sandbox uses icacls to mark writable paths; reset them with icacls "C:\path\to\dir" /setintegritylevel Medium.

To see what the sandbox can reach, ask the CLI itself: gemini -s -p "run shell command: env | grep SANDBOX" lists sandbox environment variables, and mount | grep workspace shows the mounts. Files need no export step — container sandboxes mount your project at the same absolute path, so edits land in your folder directly. To disable: drop the -s flag, unset GEMINI_SANDBOX, or remove the "sandbox" entry from settings.json; tool-level sandboxing has its own switch, "security": "toolSandboxing": false (restart required).

Gemini CLI sandbox FAQ

Related guides