Resource Limits
Kubernetes-style Resource Specs
OpenSandbox uses Kubernetes-style resource specifications for CPU and memory limits:CPU Specifications
Format:"<number>m" (millicores) or "<number>" (cores)
Examples:
"100m"= 0.1 CPU cores (100 millicores)"500m"= 0.5 CPU cores"1"= 1 full CPU core"2"= 2 CPU cores
| Workload Type | Recommended CPU | Example |
|---|---|---|
| Lightweight scripts | 100m - 250m | Simple Python/Node.js scripts |
| API services | 250m - 500m | REST API endpoints |
| Compute tasks | 500m - 2 | Data processing, ML inference |
| Heavy computation | 2+ | Training, video processing |
Memory Specifications
Format:"<number>Ki/Mi/Gi" (Kibibytes/Mebibytes/Gibibytes)
Examples:
"128Mi"= 128 Mebibytes"512Mi"= 512 Mebibytes"1Gi"= 1 Gibibyte"4Gi"= 4 Gibibytes
| Workload Type | Recommended Memory | Example |
|---|---|---|
| Minimal processes | 64Mi - 128Mi | Shell scripts, curl |
| Lightweight apps | 128Mi - 512Mi | Node.js, Python web servers |
| Standard apps | 512Mi - 2Gi | Django, Spring Boot |
| Memory-intensive | 2Gi+ | In-memory databases, ML models |
Docker Runtime Resource Controls
Process Limits
Prevent fork bombs by limiting the number of processes:null to disable the limit:
Security Capabilities
Drop dangerous Linux capabilities to reduce attack surface:drop_capabilities
drop_capabilities
Removes Linux capabilities from containers:
- AUDIT_WRITE: Prevents writing to audit log
- MKNOD: Prevents creating special files
- NET_ADMIN: Prevents network configuration changes
- NET_RAW: Prevents raw socket access
- SYS_ADMIN: Prevents most privileged operations
- SYS_MODULE: Prevents loading kernel modules
- SYS_PTRACE: Prevents process tracing
- SYS_TIME: Prevents system time changes
- SYS_TTY_CONFIG: Prevents TTY configuration
no_new_privileges
no_new_privileges
Prevents processes from gaining additional privileges through setuid/setgid bits or capabilities.When enabled:
- Blocks privilege escalation attacks
- Prevents execution of setuid binaries
- Improves container security posture
AppArmor Profile
AppArmor Profile
Apply mandatory access control using AppArmor:Leave empty (
"") to use Docker’s default profile or disable AppArmor.Seccomp Profile
Seccomp Profile
Restrict system calls using Seccomp:
- Empty string: Use Docker’s default seccomp profile
- Absolute path: Load custom seccomp profile from file
Kubernetes Resource Pooling
Pool Configuration
Configure resource pools with capacity limits:Capacity Parameters
| Parameter | Description | Purpose |
|---|---|---|
bufferMin | Minimum available resources | Ensures instant provisioning |
bufferMax | Maximum available resources | Controls standby cost |
poolMin | Minimum total pool size | Baseline capacity |
poolMax | Maximum total pool size | Resource ceiling |
poolMin: 5→ Always maintain 5 total resourcespoolMax: 20→ Never exceed 20 total resourcesbufferMin: 2→ Keep at least 2 ready for allocationbufferMax: 10→ Don’t pre-warm more than 10
Resource Requests vs Limits
- Requests: Set to typical usage for scheduling
- Limits: Set to maximum expected usage
- Ratio: Keep limits 1.5-2x requests for burstability
Network Policy Resource Management
Egress Control
Control network egress to manage bandwidth and security:- Docker bridge mode (
network_mode = "bridge") - Egress sidecar configured:
Sidecar Resource Impact
When using network policies, an egress sidecar is injected: Additional Resources:- CPU overhead: ~50m
- Memory overhead: ~64Mi
- Network namespace sharing
Storage and Volume Management
Host Path Allowlist
Restrict bind mount locations for security:- Empty list = all paths allowed (not recommended for production)
- Restrict to specific directories
- Use separate paths per team/project
- Avoid mounting sensitive system paths
Volume Resource Limits
While OpenSandbox doesn’t directly limit disk space, you can:- Use Docker storage driver limits:
- Mount limited tmpfs:
- Set PVC quotas in Kubernetes:
Timeout and Expiration Management
Sandbox TTL
Set automatic expiration for resource cleanup:Renew Expiration
Extend sandbox lifetime before expiration:Failed Sandbox Cleanup
Configure cleanup for failed sandboxes:Best Practices
Right-size resource allocations
Right-size resource allocations
Avoid over-provisioning:
- Start with conservative limits (e.g., 250m CPU, 256Mi RAM)
- Monitor actual usage via metrics
- Adjust based on real workload patterns
- Use requests < limits for burstability
Configure resource pools efficiently
Configure resource pools efficiently
Pool sizing strategy:
- Set
bufferMinto expected concurrent demand - Set
bufferMaxto handle burst traffic - Set
poolMaxto cluster capacity limits - Monitor pool allocation rates
Implement security hardening
Implement security hardening
Production security baseline:Test security settings before deploying to production.
Set appropriate timeouts
Set appropriate timeouts
Timeout guidelines:
- Short-lived tasks: 300-900 seconds (5-15 minutes)
- Interactive sessions: 1800-3600 seconds (30-60 minutes)
- Long-running jobs: 3600-7200 seconds (1-2 hours)
- Background services: Use longer TTLs with renewal
Monitor and adjust quotas
Monitor and adjust quotas
Continuous optimization:
- Collect metrics over time
- Analyze resource usage patterns
- Identify underutilized resources
- Adjust limits to improve density
- Monitor for resource contention
- Prometheus for metrics aggregation
- Grafana for visualization
- Kubernetes resource quotas
- Custom monitoring scripts
Environment Variables
| Variable | Description | Default |
|---|---|---|
SANDBOX_CONFIG_PATH | Override config file location | ~/.sandbox.toml |
DOCKER_HOST | Docker daemon URL | unix:///var/run/docker.sock |
PENDING_FAILURE_TTL | TTL for failed sandboxes (seconds) | 3600 |