gVisor is an application kernel that provides a substantial security boundary between the application and the host kernel. It implements most of the Linux system call interface in userspace, acting as a sandbox.
For the TEE, gVisor provides:
- Hardware virtualization - Prevents kernel exploits
- Syscall interception - Filters dangerous system calls
- Process isolation - Each execution is fully isolated
- Resource containment - Hard limits on CPU, memory, I/O
| Feature | With gVisor | Without gVisor |
|---|---|---|
| Security | VM-level isolation | Container-level only |
| Kernel access | Blocked | Accessible |
| Exploits | Contained | Can affect host |
| Performance | ~1% overhead | No overhead |
| Startup time | +50-100ms | Baseline |
| Platform | Linux only | All platforms |
- Production deployments
- Multi-tenant environments
- Untrusted user code
- Security-critical applications
- Linux hosts
- Local development on macOS/Windows
- Quick testing and iteration
- Debugging issues
- Non-Linux systems
# Install gVisor (runsc)
curl -fsSL https://gvisor.dev/archive.key | \
sudo gpg --dearmor -o /usr/share/keyrings/gvisor-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/gvisor-archive-keyring.gpg] \
https://storage.googleapis.com/gvisor/releases release main" | \
sudo tee /etc/apt/sources.list.d/gvisor.list
sudo apt-get update
sudo apt-get install -y runsc
# Configure Docker to use gVisor
sudo runsc install
sudo systemctl restart docker
# Verify installation
docker run --rm --runtime=runsc hello-worldgVisor requires Linux kernel features and cannot run on macOS or Windows. For development on these platforms:
- Use the dev compose file:
make run-dev - Or set
DISABLE_GVISOR=true
# Use the pre-configured dev environment
make run-dev
# Or manually
docker-compose -f docker-compose.dev.yml up -dEdit docker-compose.yml:
services:
tee-api:
environment:
- DISABLE_GVISOR=true # Add this lineOr set when running:
DISABLE_GVISOR=true docker-compose upcd services/api
DISABLE_GVISOR=true go run cmd/api/main.goWhen gVisor is disabled, you'll see prominent warnings:
╔══════════════════════════════════════════════════════════════════════════════╗
║ ║
║ ⚠️ ⚠️ ⚠️ SECURITY WARNING: gVisor is DISABLED ⚠️ ⚠️ ⚠️ ║
║ ║
║ Code execution is NOT sandboxed with hardware virtualization! ║
║ User code can potentially: ║
║ - Access the host kernel ║
║ - Exploit kernel vulnerabilities ║
║ - Perform timing attacks ║
║ ║
║ DO NOT USE IN PRODUCTION! ║
╚══════════════════════════════════════════════════════════════════════════════╝
Additionally, every execution will log:
⚠️ WARNING: gVisor is DISABLED - execution is NOT sandboxed!
Check if gVisor is enabled:
# Check Docker runtime config
docker info | grep -i runtime
# Should show:
# Runtimes: io.containerd.runc.v2 runc runsc
# Test gVisor execution
docker run --rm --runtime=runsc alpine echo "gVisor works!"Check TEE logs:
docker-compose logs tee-api | head -20
# With gVisor:
# ✓ gVisor sandboxing: ENABLED
# Without gVisor:
# ⚠️ WARNING: gVisor is DISABLEDCause: gVisor not installed or not configured in Docker
Solution:
# Install gVisor
sudo apt-get install -y runsc
# Configure Docker
sudo runsc install
sudo systemctl restart dockerCause: Docker daemon doesn't have permission to use runsc
Solution:
# Ensure runsc is in PATH
which runsc # Should show /usr/bin/runsc
# Restart Docker daemon
sudo systemctl restart docker
# Try again
docker run --rm --runtime=runsc hello-worldExpected behavior. gVisor adds 50-100ms per container startup due to the security boundary. This is acceptable for the added security.
Disable gVisor for development:
make run-dev # Uses docker-compose.dev.yml with DISABLE_GVISOR=trueBased on production testing:
| Metric | Without gVisor | With gVisor | Delta |
|---|---|---|---|
| Setup time | 500-800ms | 600-900ms | +100ms |
| Execution time | 100ms | 150ms | +50ms |
| Memory overhead | 128MB | 133MB | +5MB |
| CPU overhead | 0.5 core | 0.51 core | +1% |
Conclusion: gVisor adds minimal overhead (~50-100ms per execution) for substantial security benefits.
User Code
↓
Deno Runtime
↓
gVisor (runsc) - ← Security boundary
↓
Host Kernel
↓
Hardware
User Code
↓
Deno Runtime
↓
Container namespace - ← Weaker boundary
↓
Host Kernel - ← Can be exploited
↓
Hardware
- Always use gVisor in production
- Never disable gVisor for untrusted code
- Use dev mode only on trusted networks
- Monitor logs for disabled warnings
- Regularly update gVisor:
sudo apt-get update && sudo apt-get upgrade runsc