Sandbox Tool
The sandbox provides an isolated execution environment for running untrusted code and commands securely.Overview
Sandboxing protects your system by:- Isolating execution: Commands run in separate container
- Limiting access: Restricted file system and network access
- Resource control: CPU and memory limits
- Clean environment: Fresh state for each session
Supported Providers
Docker
Status: Recommended for most users Requirements:- Docker Desktop or Docker Engine
- Sufficient disk space for container image
Podman
Status: Alternative to Docker Requirements:- Podman installed and configured
- Rootless mode supported
macOS Seatbelt
Status: macOS native sandboxing Requirements:- macOS operating system
- System Integrity Protection enabled
No Sandbox
Status: Not recommended (development only) Setup:Configuration
Environment Variable
The primary configuration method:Settings File
Configure insettings.json:
Build Configuration
Default Image:How It Works
Execution Flow
Container Lifecycle
-
Session Start:
- Pull/build sandbox image
- Start container
- Mount project directory
- Set up environment
-
Command Execution:
- Send command to container
- Execute in isolated environment
- Stream output back to CLI
- Handle errors and timeouts
-
Session End:
- Stop container
- Clean up resources
- Preserve project changes
Customizing the Sandbox
Custom Dockerfile
Note: This requires working from the source code repository, not an npm-installed package.Requirements
-
Clone the Qwen Code repository:
-
Install dependencies:
-
Build the project:
-
Link the CLI globally:
Create Custom Dockerfile
Create.qwen/sandbox.Dockerfile in your project:
Build Custom Image
From your project root:Verify Custom Image
Restore Official CLI
After testing custom sandbox:Sandbox Limitations
File System
Accessible:- Project directory (mounted read-write)
- Temp directory within container
- Standard Unix paths
- Home directory outside project
- System directories
- Other projects
Network
Default:- Outbound connections allowed
- No inbound connections
- DNS resolution available
Performance
Overhead:- Container startup: ~1-2 seconds
- Command execution: Minimal (less than 100ms)
- File I/O: Slightly slower than native
- Keep container running between commands
- Use
.dockerignoreto exclude large files - Cache package installations in image
Security Benefits
Isolation
✅ Protected:- System files
- Other projects
- User data
- Network resources
- Malicious scripts
- Unexpected side effects
- Resource consumption
- File system modifications
Use Cases
When to use sandbox:-
Untrusted code:
-
Experimental commands:
-
Package installation:
-
Build processes:
- Trusted, well-known commands (
git status,ls) - Simple file operations
- Built-in tools (read_file, write_file)
- Development on personal projects
Troubleshooting
Image Build Fails
Error:Failed to build sandbox image
Solutions:
- Check Docker/Podman is running
- Verify internet connectivity
- Check disk space:
df -h - Clear Docker cache:
docker system prune - Retry build:
npm run build:sandbox
Container Won’t Start
Error:Container failed to start
Solutions:
- Check Docker daemon:
docker ps - Review logs:
docker logs <container-id> - Restart Docker Desktop
- Check resource limits
Permission Errors
Error:Permission denied in sandbox
Solutions:
- Check file permissions in project
- Verify mount points
- Use rootless container if possible
- Check SELinux/AppArmor policies
Performance Issues
Symptoms: Slow command execution Solutions:- Check Docker resource allocation
- Reduce mounted directory size
- Use
.dockerignore: - Increase Docker Desktop resources
Network Issues
Error:Network request failed in sandbox
Solutions:
- Check Docker network mode
- Verify DNS resolution:
docker run alpine nslookup google.com - Check firewall rules
- Test with
--network host(temporary)
Best Practices
1. Keep Images Updated
2. Optimize Image Size
3. Cache Dependencies
4. Use .dockerignore
5. Monitor Resources
Configuration Reference
Full Settings
Environment Variables
Implementation
Key Files:scripts/build_sandbox.js- Build scriptDockerfile- Sandbox image definitionpackages/core/src/services/shellExecutionService.ts- Execution routing
Shell Execution Service
Next Steps
- Shell Tool - Shell command execution
- Development Setup - Setting up sandbox for development
- Configuration System - Advanced configuration
