flux-sandbox代码仓
| Files | Last commit | Last update |
|---|---|---|
| 1 day ago | ||
| 3 days ago | ||
| 1 day ago | ||
| 1 day ago | ||
| 24 days ago | ||
| 2 days ago | ||
| 3 months ago | ||
| 1 day ago | ||
| 1 day ago | ||
| 1 day ago | ||
| 3 days ago | ||
| 3 days ago | ||
| 3 months ago | ||
| 1 day ago | ||
| 2 days ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 1 day ago | ||
| 3 days ago |
SandboxSched
English | 中文
A high-performance Kubernetes sandbox scheduling engine that serves as a runtime backend for OpenSandbox, built for AI agent workloads that demand low-latency, high-throughput sandbox lifecycle management.
SandboxSched does not expose a user-facing API directly. Instead, it is consumed
through the OpenSandbox Server's flux runtime: users create sandboxes via the
OpenSandbox SDK, and the Server forwards requests over gRPC for scheduling and
lifecycle management.
Components
After the merge the control plane is a single multi-active component: the former controller (gRPC gateway) and scheduler (scheduling engine) processes are merged into one binary (flux-sandbox-scheduler). Replicas share the PostgreSQL intent ledger and the mandatory Redis view layer; periodic tasks run on the Lease holder only.
| Component | Role | Deployment |
|---|---|---|
| flux-sandbox-scheduler | Merged control plane: FastPath HTTP :9090 / SandboxProvider gRPC :9091 / agent heartbeat intake :9092; fleet orchestration, sandbox scheduling, intent-ledger state machine | Deployment (multi-replica, multi-active) |
| flux-sandbox-agent | Data-plane: manages sandbox instances via runtime API | Dispatched by the merged control plane |
| flux-sandbox-let | Per-node daemon: the sandbox agent's business logic (sandbox lifecycle HTTP API :5758, per-slot heartbeat reporting) merged with the orphan sandbox cleanup | DaemonSet |
Storage dependencies: PostgreSQL 16 (intent ledger,
POSTGRES_DSN) and Redis 7 (view layer,REDIS_ADDR— required: the scheduler refuses to start without one; the legacy no-Redis mode was removed). Render the bundled instances (scheduler.postgres.enabled/scheduler.redis.enabled) or point at external ones.
Project Structure
cmd/ # entry points for each binary
internal/
flux-sandbox-controller/ # control plane: routing, gRPC contract (merged in-process)
scheduler/ # scheduling engine, ledger state machine, fleet orchestration (merged control plane)
merged/ # merged assembly: inline calls, cross-replica ops, gRPC reads, leader tasks
intentstore/ # intent ledger (PostgreSQL/sqlite, CAS state machine)
viewlayer/ # Redis view layer (liveness/self-description/capacity arbitration)
agent/ # data-plane: runtime management (containerd, E2B)
sandboxlet (cmd/flux-sandbox-let) # per-node daemon: agent business logic + orphan cleanup
api/
proto/v1/ # gRPC service definitions (generated)
v1alpha1/ # CRD types
charts/sandboxsched/ # Helm chart (recommended deployment)
config/ # raw Kubernetes deployment manifests
build/ # Dockerfiles
docs/design/ # System design document
Quick Start
SandboxSched is used through OpenSandbox as the entry point. The end-to-end flow
is: OpenSandbox SDK → OpenSandbox Server (flux runtime) → SandboxSched Controller.
Prerequisites
- A Kubernetes cluster (1.28+) with
kubectlaccess - containerd runtime on worker nodes
- Helm 3.14+ (recommended deployment method)
- Go 1.25+ (only when building from source)
- Python 3.10+ (required by OpenSandbox SDK)
- Docker (for building images, only when building from source)
1. Build Images (skip when using published images)
All SandboxSched components are deployed as container images. When building
from source, make build compiles all binaries to the bin/ directory, then
build and push Docker images:
# Compile binaries and build images
make docker-build
# Push to a registry accessible by the cluster
make docker-push REGISTRY=registry.example.com TAG=v0.1.0
You can also build images individually:
make build
docker build -f build/Dockerfile.scheduler -t flux-sandbox/scheduler:latest .
docker build -f build/Dockerfile.sandboxlet -t flux-sandbox/sandboxlet:latest .
cmd/flux-sandbox-controlleris a deprecation stub since P4 (prints a warning and exits 1); the merged control-plane entrypoint iscmd/flux-sandbox-scheduler.
Push the images to a registry accessible by the cluster after building.
2. Deploy SandboxSched
Option 1: Helm (recommended)
The default per-component repositories are
flux-sandbox/{scheduler,flux-sandbox-let}, aligned with the openFuyao
CI publish paths. When using the official images, set the global.imageRegistry
prefix and enable the bundled ledger/view stores (or point at external ones):
helm install flux-sandbox ./charts/sandboxsched \
--namespace flux-system \
--create-namespace \
--set global.imageRegistry=cr.openfuyao.cn/openfuyao \
--set scheduler.postgres.enabled=true \
--set scheduler.redis.enabled=true \
--set scheduler.redis.address=flux-sandbox-redis:6379
CRDs are installed automatically with the chart. Image versions, E2B configuration, replica counts, scheduling constraints and more can be customized via values — see the chart README.
Option 2: Raw manifests
# Create namespace
kubectl create namespace flux-system
# Install CRDs
kubectl apply -f charts/sandboxsched/crds/
# Apply component manifests
# flux-sandbox-let ships via the helm chart (DaemonSet); no raw manifests needed
Verify readiness
kubectl wait --for=condition=Ready pod -n flux-system -l app=flux-sandbox-scheduler --timeout=60s
kubectl wait --for=condition=Ready pod -n flux-system -l app=flux-sandbox-let --timeout=60s
3. Create a SandboxGroup
A SandboxGroup defines the resource profile and capacity for a set of sandboxes.
The merged control plane maps each group to one Agent fleet (no shard split); the
leader provisions and reconciles the Agent Pods. Once the group reaches Ready,
sandboxes can be created.
Note: In a standard k8s environment,
RUNTIME_TYPE=containerdandexecdImagemust be set explicitly. The controller defaults to thee2bruntime type, which does not mount the containerd socket or inject the execd init container, leaving the agent unable to create containers.
kubectl apply -f - <<EOF
apiVersion: sandbox.flux.io/v1alpha1
kind: SandboxGroup
metadata:
name: sg-1u1g
namespace: flux-system
spec:
capacity:
agentPodMin: 1
agentPodMax: 3
sandboxBufferMin: 1
maxSandboxesPerPod: 5
sandboxResources:
requests: { cpu: "1", memory: "2Gi" }
limits: { cpu: "1", memory: "2Gi" }
agentEnv:
RUNTIME_TYPE: "containerd"
execdImage: "opensandbox/execd:v1.0.20"
EOF
Wait for the SandboxGroup to be ready:
kubectl wait --for=condition=Ready sandboxgroup sg-1u1g -n flux-system --timeout=120s
The requests/limits in sandboxResources determine the per-sandbox resource
profile and are the single source of truth — caller-supplied (OpenSandbox SDK)
resource parameters are ignored. See the
design document
for scheduling internals.
4. Deploy OpenSandbox Server
Clone the openFuyao/opensandbox repository, then build and deploy the Server:
git clone https://gitcode.com/openFuyao/opensandbox.git
cd opensandbox/server
# Build OpenSandbox Server image
docker build -f Dockerfile.flux -t opensandbox-server:flux .
Push the image to a registry accessible by the cluster after building.
Create a config file config.toml:
[server]
host = "0.0.0.0"
port = 8080
api_key = "your-api-key"
[runtime]
type = "flux"
execd_image = "opensandbox/execd:v1.0.20"
[flux_sandbox]
endpoint = "flux-sandbox-scheduler.flux-system.svc:9091"
timeout_seconds = 15
use_tls = false
[ingress]
mode = "direct"
Deploy to the cluster:
kubectl create configmap opensandbox-server-config -n flux-system --from-file=config.toml
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: opensandbox-server
namespace: flux-system
spec:
replicas: 1
selector:
matchLabels:
app: opensandbox-server
template:
metadata:
labels:
app: opensandbox-server
spec:
containers:
- name: server
image: opensandbox-server:flux
imagePullPolicy: IfNotPresent
args: ["--config", "/etc/opensandbox/config.toml"]
ports:
- name: http
containerPort: 8080
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 5
periodSeconds: 10
volumeMounts:
- name: config
mountPath: /etc/opensandbox
volumes:
- name: config
configMap:
name: opensandbox-server-config
---
apiVersion: v1
kind: Service
metadata:
name: opensandbox-server
namespace: flux-system
spec:
selector:
app: opensandbox-server
ports:
- name: http
port: 8080
targetPort: http
EOF
kubectl wait --for=condition=Ready pod -n flux-system -l app=opensandbox-server --timeout=60s
5. Prepare Sandbox Images
The agent needs to pull the sandbox image and execd image from the cluster nodes when creating sandboxes. Ensure the following images are available on all worker nodes:
# Sandbox runtime image (used by the SDK example)
docker pull python:3.11
# execd image (specified by execdImage in the SandboxGroup)
docker pull opensandbox/execd:v1.0.20
Ensure images are pushed to a registry accessible by the cluster, or pre-pulled on all worker nodes.
6. Create a Sandbox via SDK
Install the OpenSandbox Python SDK:
pip install opensandbox
Create a sandbox, passing extensions.sandboxGroup to route to a SandboxGroup:
import asyncio
from datetime import timedelta
from opensandbox import Sandbox
from opensandbox.config import ConnectionConfig
async def main():
config = ConnectionConfig(
domain="<server-address>:8080", # OpenSandbox Server address
api_key="your-api-key",
)
# extensions.sandboxGroup routes to the SandboxGroup named "sg-1u1g"
async with await Sandbox.create(
"python:3.11",
connection_config=config,
entrypoint=["python", "-m", "http.server"],
env={"PYTHONUNBUFFERED": "1"},
timeout=timedelta(minutes=30),
extensions={"sandboxGroup": "sg-1u1g"},
) as sandbox:
# Run a command
result = await sandbox.commands.run("echo 'Hello SandboxSched!'")
print(result.logs.stdout[0].text)
# Get a port endpoint
endpoint = await sandbox.get_endpoint(8080)
print(f"endpoint: {endpoint.endpoint}")
asyncio.run(main())
See the OpenSandbox Python SDK for the full SDK API.
User Guide
For the complete user guide (features, runtime modes, deployment & operations, SDK usage, etc.), see the SandboxSched User Guide.
Design Document
The full system design is in docs/design/0001-FluxSandbox沙箱集群调度引擎系统设计.md.
Roadmap
This project has moved to the new repository SandboxSched. Future roadmap planning and development are tracked there.
Contributing
Contributions are welcome. Please open an issue or submit a pull request on gitcode.