Sandbox Mode
Execute code safely in an isolated environment.
What is Sandbox Mode?
Sandbox mode allows Gemini to write and test code in a secure, isolated environment without affecting your system.
Basic Usage
/gemini-cli:sandbox create a Python script that sorts a listHow It Works
- Request → You ask for code to be created/tested
- Generation → Gemini writes the code
- Execution → Code runs in isolated environment
- Results → Output returned safely
Use Cases
Algorithm Testing
/gemini-cli:sandbox implement and test quicksort in JavaScriptData Processing
/gemini-cli:sandbox parse this CSV and show statistics: [data]Proof of Concepts
/gemini-cli:sandbox create a working web scraper exampleSafety Features
- Isolated Execution: No access to your file system
- Resource Limits: CPU and memory constraints
- Time Limits: Prevents infinite loops
- No Network: Cannot make external requests
Supported Languages
- Python
- JavaScript/Node.js
- Ruby
- Go
- Java
- C++
- More coming soon!
Best Practices
1. Be Specific
// Good create a function that validates email addresses with tests // Vague make something that checks emails2. Include Test Cases
implement binary search with edge case handling and show test results3. Iterative Development
// First iteration create a basic REST API // Refine add authentication to the API // Test show example requests and responsesLimitations
- No file system access
- No network requests
- Limited execution time (30s)
- Memory limit (512MB)
Examples
Testing Algorithms
/gemini-cli:sandbox benchmark bubble sort vs quick sort with 1000 itemsLearning Code
/gemini-cli:sandbox show me how promises work in JavaScript with examplesDebugging
/gemini-cli:sandbox why does this code fail: [paste code]