OpenSandbox Kubernetes Controller
OpenSandbox Kubernetes Controller is a Kubernetes operator that manages sandbox environments through custom resources. It provides automated sandbox lifecycle management, resource pooling for fast provisioning, batch sandbox creation, and optional task orchestration capabilities in Kubernetes clusters.
Key Features
- Flexible Sandbox Creation: Choose between pooled and non-pooled sandbox creation modes
- Batch and Individual Delivery: Support both single sandbox (for real-user interactions) and batch sandbox delivery (for high-throughput agentic-RL scenarios)
- Optional Task Scheduling: Integrated task orchestration with optional shard task templates for heterogeneous task distribution and customized sandbox delivery (e.g., process injection)
- Resource Pooling: Maintain pre-warmed resource pools for rapid sandbox provisioning
- Comprehensive Monitoring: Real-time status tracking of sandboxes and tasks
Features
Batch Sandbox Management
The BatchSandbox custom resource allows you to create and manage multiple identical sandbox environments. Key capabilities include:
- Flexible Creation Modes: Support both pooled (using resource pools) and non-pooled sandbox creation
- Single and Batch Delivery: Create single sandboxes (replicas=1) or batches of sandboxes (replicas=N) as needed
- Scalable Replica Management: Easily control the number of sandbox instances through replica configuration
- Automatic Expiration: Set TTL (time-to-live) for automatic cleanup of expired sandboxes
- Optional Task Scheduling: Built-in task execution engine with support for optional task templates
- Detailed Status Reporting: Comprehensive metrics on replicas, allocations, and task states
Resource Pooling
The Pool custom resource maintains a pool of pre-warmed compute resources to enable rapid sandbox provisioning:
- Configurable buffer sizes (minimum and maximum) to balance resource availability and cost
- Pool capacity limits to control overall resource consumption
- Automatic resource allocation and deallocation based on demand
- Real-time status monitoring showing total, allocated, and available resources
Task Orchestration
Integrated task management system that executes custom workloads within sandboxes:
- Optional Execution: Task scheduling is completely optional - sandboxes can be created without tasks
- Process-Based Tasks: Support for process-based tasks that execute within the sandbox environment
- Heterogeneous Task Distribution: Customize individual tasks for each sandbox in a batch using shardTaskPatches
Advanced Scheduling
Intelligent resource management features:
- Minimum and maximum buffer settings to ensure resource availability while controlling costs
- Pool-wide capacity limits to prevent resource exhaustion
- Automatic scaling based on demand
Relationship with kubernates-sigs/agent-sandbox
BatchSandbox does not duplicate the basic functionality of Agent-Sandbox, but rather complements it with additional enhanced capabilities:
- Batch Sandbox Semantics: Significantly improves Sandbox delivery throughput in scenarios such as Reinforcement Learning (RL) training
- Task Scheduling Capability: Enables differentiated Sandbox delivery through Task scheduling, such as injecting custom processes into containers before Sandbox delivery
Therefore, you can choose the appropriate project as your Sandbox underlying runtime based on your specific application scenarios.
Performance Testing
Performance comparison test of BatchSandbox and Sig Agent-Sandbox in terms of throughput.
Test Environment
Controller Component Configuration
- Resource Specifications: request: 12C32G, limit: 16C64G
- Concurrency Configuration:
- Sig Agent-Sandbox: 3 controllers (sandbox, sandboxclaim, sandboxwarmppool), no concurrency configuration provided in the code, default value is 1
- BatchSandbox: 2 controllers, batchsandbox controller concurrency is 32, pool controller concurrency is 1
Pool Configuration
- Image: busybox:latest
- Resource Specifications: 0.1C256MB
Additional Note: Although the batchsandbox-controller of BatchSandbox has a concurrency of 32, only one BatchSandbox object was created in the test cases, which is actually equivalent to a concurrency of 1. Therefore, in terms of concurrency, BatchSandbox is consistent with SIG Agent-Sandbox.
Performance Comparison Results
When both use resource pools, the total time comparison for delivering 100 Sandboxes:
| Test Scenario | Total Time (seconds) |
|---|---|
| SIG Agent-Sandbox (concurrency=1) | 76.35 |
| SIG Agent-Sandbox (concurrency=10) | 23.17 |
| SIG Agent-Sandbox (concurrency=50) | 33.85 |
| BatchSandbox | 0.92 |
Analysis
Core Difference: The time complexity of Sig Agent-Sandbox and BatchSandbox for batch delivery of N Sandboxes is O(N) and O(1) respectively.
Sig Agent-Sandbox Architecture
- Each Sandbox delivery process requires the following write operations (total write operations are proportional to Sandbox scale):
- Create a SandboxClaim
- Create a Sandbox
- Update Pod once (adopt Pod from resource pool)
- Update Sandbox Status once
- Update SandboxClaim Status once
BatchSandbox Architecture
- Each batch Sandbox delivery process requires the following write operations (total write operations are independent of Sandbox scale):
- Create a BatchSandbox
- Update BatchSandbox annotation once (write batch allocation results)
- Update BatchSandbox status once
Getting Started

Prerequisites
- go version v1.24.0+
- docker version 17.03+
- kubectl version v1.11.3+
- Access to a Kubernetes v1.22.4+ cluster
If you don't have access to a Kubernetes cluster, you can use kind to create a local Kubernetes cluster for testing purposes. Kind runs Kubernetes nodes in Docker containers, making it easy to set up a local development environment.
To install kind:
- Download the release binary for your OS from the releases page and move it into your
$PATH - Or use a package manager:
- macOS (Homebrew):
brew install kind - Windows (winget):
winget install Kubernetes.kind
- macOS (Homebrew):
After installing kind, create a cluster with:
kind create clusterThis command creates a single-node cluster by default. To interact with it, use kubectl with the generated kubeconfig.
Important Note for Kind Users: If you're using a kind cluster, you need to load the controller and task-executor images into the kind node after building them with make docker-build. This is because kind runs Kubernetes nodes in Docker containers and cannot directly access images from your local Docker daemon.
Load the images into the kind cluster with:
kind load docker-image <controller-image-name>:<tag>
kind load docker-image <task-executor-image-name>:<tag>For example, if you built your images with make docker-build IMG=my-controller:latest, you would load them with:
kind load docker-image my-controller:latestDelete the cluster when you're done with:
kind delete clusterFor more detailed instructions on using kind, please refer to the official kind documentation.
Deployment
This project requires two separate images - one for the controller and another for the task-executor component.
Build and push your images:
sh# Build and push the controller image make docker-build docker-push IMG=<some-registry>/opensandbox-controller:tag # Build and push the task-executor image make docker-build-task-executor docker-push-task-executor TASK_EXECUTOR_IMG=<some-registry>/opensandbox-task-executor:tagNOTE: These images ought to be published in the personal registry you specified. And it is required to have access to pull the images from the working environment. Make sure you have the proper permission to the registry if the above commands don't work.
Install the CRDs into the cluster:
shmake installDeploy the Manager to the cluster:
shmake deploy IMG=<some-registry>/opensandbox-controller:tag TASK_EXECUTOR_IMG=<some-registry>/opensandbox-task-executor:tagNOTE: you may need to grant yourself cluster-admin privileges or be logged in as admin to ensure you have cluster-admin privileges before running the commands.
Important Note for Kind Users: If you're using a kind cluster, you need to load both images into the kind node after building them:
kind load docker-image <controller-image-name>:<tag>
kind load docker-image <task-executor-image-name>:<tag>Creating BatchSandbox and Pool Resources
Basic Example
Create a simple non-pooled sandbox without task scheduling:
apiVersion: sandbox.opensandbox.io/v1alpha1
kind: BatchSandbox
metadata:
name: basic-batch-sandbox
spec:
replicas: 2
template:
spec:
containers:
- name: sandbox-container
image: nginx:latest
ports:
- containerPort: 80Apply the batch sandbox configuration:
kubectl apply -f basic-batch-sandbox.yamlCheck the status of your batch sandbox:
kubectl get batchsandbox basic-batch-sandbox -o wideExample output:
NAME DESIRED TOTAL ALLOCATED READY EXPIRE AGE
basic-batch-sandbox 2 2 2 2 <none> 5mStatus field explanations:
- DESIRED: The number of sandboxes requested
- TOTAL: The total number of sandboxes created
- ALLOCATED: The number of sandboxes successfully allocated
- READY: The number of sandboxes ready for use
- EXPIRE: Expiration time (empty if not set)
- AGE: Time since the resource was created
After the sandboxes are ready, you can find the endpoint information in the annotations:
kubectl get batchsandbox basic-batch-sandbox -o jsonpath='{.metadata.annotations.sandbox\.opensandbox\.io/endpoints}'This will show the IP addresses of the delivered sandboxes.
Advanced Examples
Pooled Sandbox Without Task
First, create a resource pool:
apiVersion: sandbox.opensandbox.io/v1alpha1
kind: Pool
metadata:
name: example-pool
spec:
template:
spec:
containers:
- name: sandbox-container
image: nginx:latest
ports:
- containerPort: 80
capacitySpec:
bufferMax: 10
bufferMin: 2
poolMax: 20
poolMin: 5Apply the pool configuration:
kubectl apply -f pool-example.yamlCreate a batch of sandboxes using the pool:
apiVersion: sandbox.opensandbox.io/v1alpha1
kind: BatchSandbox
metadata:
name: pooled-batch-sandbox
spec:
replicas: 3
poolRef: example-poolApply the batch sandbox configuration:
kubectl apply -f pooled-batch-sandbox.yamlPooled Sandbox With Heterogeneous Tasks
Create a batch of sandboxes with process-based heterogeneous tasks. For task execution to work properly, the task-executor must be deployed as a sidecar container in the pool template and share the process namespace with the sandbox container:
First, create a resource pool with the task-executor sidecar:
apiVersion: sandbox.opensandbox.io/v1alpha1
kind: Pool
metadata:
name: task-example-pool
spec:
template:
spec:
shareProcessNamespace: true
containers:
- name: sandbox-container
image: ubuntu:latest
command: ["sleep", "3600"]
- name: task-executor
image: <task-executor-image>:<tag>
securityContext:
capabilities:
add: ["SYS_PTRACE"]
capacitySpec:
bufferMax: 10
bufferMin: 2
poolMax: 20
poolMin: 5Create a batch of sandboxes with process-based heterogeneous tasks using the pool we just created:
apiVersion: sandbox.opensandbox.io/v1alpha1
kind: BatchSandbox
metadata:
name: task-batch-sandbox
spec:
replicas: 2
poolRef: task-example-pool
taskTemplate:
spec:
process:
command: ["echo", "Default task"]
shardTaskPatches:
- spec:
process:
command: ["echo", "Custom task for sandbox 1"]
- spec:
process:
command: ["echo", "Custom task for sandbox 2"]
args: ["with", "additional", "arguments"]Apply the batch sandbox configuration:
kubectl apply -f task-batch-sandbox.yamlCheck the status of your batch sandbox with tasks:
kubectl get batchsandbox task-batch-sandbox -o wideExample output:
NAME DESIRED TOTAL ALLOCATED READY TASK_RUNNING TASK_SUCCEED TASK_FAILED TASK_UNKNOWN EXPIRE AGE
task-batch-sandbox 2 2 2 2 0 2 0 0 <none> 5mTask status field explanations:
- TASK_RUNNING: The number of tasks currently executing
- TASK_SUCCEED: The number of tasks that have completed successfully
- TASK_FAILED: The number of tasks that have failed
- TASK_UNKNOWN: The number of tasks with unknown status
When you delete a BatchSandbox with running tasks, the controller will first stop all tasks before deleting the BatchSandbox resource. Once all tasks are successfully terminated, the BatchSandbox will be completely removed, and the sandboxes will be returned to the pool for reuse.
To delete the BatchSandbox:
kubectl delete batchsandbox task-batch-sandboxYou can monitor the deletion process by watching the BatchSandbox status:
kubectl get batchsandbox task-batch-sandbox -wMonitoring Resources
Check the status of your pools and batch sandboxes:
# View pool status
kubectl get pools
# View batch sandbox status
kubectl get batchsandboxes
# Get detailed information about a specific resource
kubectl describe pool example-pool
kubectl describe batchsandbox example-batch-sandboxProject Structure
├── api/
│ └── v1alpha1/ # Custom resource definitions (BatchSandbox, Pool)
├── cmd/
│ ├── controller/ # Main controller manager entry point
│ └── task-executor/ # Task executor binary
├── config/
│ ├── crd/ # Custom resource definitions manifests
│ ├── default/ # Default configuration for controller deployment
│ ├── manager/ # Controller manager configuration
│ ├── rbac/ # Role-based access control manifests
│ └── samples/ # Sample YAML manifests for resources
├── hack/ # Development scripts and tools
├── images/ # Documentation images
├── internal/
│ ├── controller/ # Core controller implementations
│ ├── scheduler/ # Resource allocation and scheduling logic
│ ├── task-executor/ # Task execution engine internals
│ └── utils/ # Utility functions and helpers
├── pkg/
│ └── task-executor/ # Shared task executor packages
└── test/ # Test suites and utilitiesContributing
We welcome contributions to the OpenSandbox Kubernetes Controller project. Please feel free to submit issues, feature requests, and pull requests.
NOTE: Run make help for more information on all potential make targets
More information can be found via the Kubebuilder Documentation
License
This project is open source under the Apache 2.0 License.
You can use OpenSandbox for personal or commercial projects in compliance with the license terms.
This page is sourced from:
kubernetes/README.md