Benefits of Sandboxing
Security
Prevent accidental system damage or data loss from AI-generated commands.
Isolation
Limit file system access to the project directory only.
Consistency
Ensure reproducible environments across different systems.
Safety
Reduce risk when working with untrusted code or experimental commands.
Prerequisites
Before using sandboxing, install and verify Gemini CLI:Sandboxing Methods
Choose the method that best fits your platform and container solution.- macOS Seatbelt
- Docker/Podman
macOS Seatbelt (macOS only)
Lightweight, built-in sandboxing usingsandbox-exec.Default Profile: permissive-open- Restricts writes outside project directory
- Allows most other operations
- No additional installation required
- Native macOS integration
- No container overhead
- Fast startup
- macOS only
- Less isolation than containers
Quickstart
Command Flag
Enable sandboxing for a single session:Environment Variable
true- Auto-detect methoddocker- Use Dockerpodman- Use Podmansandbox-exec- Use macOS Seatbelt
Settings File
Enable permanently insettings.json:
Configuration
Precedence Order
Settings are applied in this order (highest to lowest priority):- Command flag:
-sor--sandbox - Environment variable:
GEMINI_SANDBOX=true|docker|podman|sandbox-exec - Settings file:
"sandbox": trueintoolsobject
macOS Seatbelt Profiles
Set profile viaSEATBELT_PROFILE environment variable:
permissive-open (default)
permissive-open (default)
- Write restrictions outside project
- Network allowed
- Good for general development
permissive-proxied
permissive-proxied
- Write restrictions outside project
- Network via proxy only
- Use when you need proxy control
restrictive-open
restrictive-open
- Strict restrictions on file operations
- Network allowed
- Recommended for untrusted code
restrictive-proxied
restrictive-proxied
- Strict restrictions on file operations
- Network via proxy only
- High security with proxy control
strict-open
strict-open
- Read and write restrictions
- Network allowed
- Maximum file safety
strict-proxied
strict-proxied
- Read and write restrictions
- Network via proxy only
- Maximum security
Custom Sandbox Flags
Inject custom flags intodocker or podman commands using SANDBOX_FLAGS.
- Disable SELinux labeling (Podman)
- Add volume mounts
- Configure network settings
- Set resource limits
Linux UID/GID Handling
The sandbox automatically handles user permissions on Linux. Override with:Troubleshooting
"Operation not permitted" error
"Operation not permitted" error
Cause: Operation requires access outside sandbox boundaries.Solutions:
- Try a more permissive profile (e.g.,
permissive-openinstead ofstrict-open) - Add mount points for required directories
- Check if the operation is necessary for your use case
Missing commands in sandbox
Missing commands in sandbox
Cause: Command not installed in sandbox environment.Solutions:
- Add to custom Dockerfile for container-based sandboxing
- Install via
sandbox.bashrcconfiguration - Verify the command is available on the host
Network issues
Network issues
Cause: Sandbox profile blocks network or proxy misconfiguration.Solutions:
- Verify profile allows network (e.g.,
-openprofiles) - Check proxy configuration if using
-proxiedprofiles - Test network connectivity:
gemini -s -p "run shell command: ping -c 1 google.com"
File permission errors
File permission errors
Cause: UID/GID mismatch between host and container.Solutions:
- Set
SANDBOX_SET_UID_GID=trueto force host UID/GID - Check file ownership on host
- Verify container user has correct permissions
Sandbox not starting
Sandbox not starting
Cause: Container runtime not available or misconfigured.Solutions:
- Verify Docker/Podman is installed:
docker --versionorpodman --version - Check container service is running
- Build sandbox image if using custom image
- Try different sandbox method:
GEMINI_SANDBOX=sandbox-exec(macOS)
Debug Mode
Enable detailed logging for troubleshooting:If you have
DEBUG=true in a project’s .env file, it won’t affect Gemini CLI due to automatic exclusion. Use .gemini/.env files for Gemini CLI-specific debug settings.Inspect Sandbox Environment
Use Cases
Untrusted Code
Run and test code from unknown sources without risking your system.
Experimental Commands
Try potentially destructive commands safely in isolation.
Production Testing
Test deployment scripts without affecting production environments.
CI/CD Integration
Consistent, isolated environments for automated workflows.
Security Notes
Configuration Examples
Basic Docker Sandbox
Restrictive macOS Setup
Custom Podman with Security Options
Development Setup with UID Mapping
Related Documentation
Configuration
Full configuration options for Gemini CLI
Commands
Available slash commands and usage
Checkpointing
Combine with checkpoints for double safety
Next Steps
Enable Sandboxing
Choose your method and add to
settings.jsonTest Your Setup
Run a simple command to verify:
gemini -s -p "run shell command: echo test"