Skip to main content
OpenSandbox provides flexible resource management capabilities to control CPU, memory, and other system resources for sandboxed environments.

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
Use Cases:

Memory Specifications

Format: "<number>Ki/Mi/Gi" (Kibibytes/Mebibytes/Gibibytes) Examples:
  • "128Mi" = 128 Mebibytes
  • "512Mi" = 512 Mebibytes
  • "1Gi" = 1 Gibibyte
  • "4Gi" = 4 Gibibytes
Use Cases:

Docker Runtime Resource Controls

Process Limits

Prevent fork bombs by limiting the number of processes:
Set to null to disable the limit:

Security Capabilities

Drop dangerous Linux capabilities to reduce attack surface:
Security Features:
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
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
Apply mandatory access control using AppArmor:
Leave empty ("") to use Docker’s default profile or disable AppArmor.
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

Example Scenario:
  • poolMin: 5 → Always maintain 5 total resources
  • poolMax: 20 → Never exceed 20 total resources
  • bufferMin: 2 → Keep at least 2 ready for allocation
  • bufferMax: 10 → Don’t pre-warm more than 10

Resource Requests vs Limits

Best Practices:
  • 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:
Requirements:
  • 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
Example Total Resources:

Storage and Volume Management

Host Path Allowlist

Restrict bind mount locations for security:
Security Considerations:
  • 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:
  1. Use Docker storage driver limits:
  1. Mount limited tmpfs:
  1. 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:
Failed sandboxes in “Pending” state are automatically cleaned up after this TTL.

Best Practices

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
Testing approach:
Pool sizing strategy:
  • Set bufferMin to expected concurrent demand
  • Set bufferMax to handle burst traffic
  • Set poolMax to cluster capacity limits
  • Monitor pool allocation rates
Example calculations:
Production security baseline:
Test security settings before deploying to production.
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
Automatic cleanup:
Continuous optimization:
  1. Collect metrics over time
  2. Analyze resource usage patterns
  3. Identify underutilized resources
  4. Adjust limits to improve density
  5. Monitor for resource contention
Tools:
  • Prometheus for metrics aggregation
  • Grafana for visualization
  • Kubernetes resource quotas
  • Custom monitoring scripts

Environment Variables