Architecture
How It Works
- Backend requests sandbox: POST
/api/sandboxeswithsandbox_idandthread_id - Provisioner creates Pod: Deploys sandbox container with mounted volumes
- Service created: NodePort service exposes pod on dynamic port
- Backend accesses sandbox: Direct HTTP access via
http://NODE_HOST:{NodePort} - Cleanup: DELETE
/api/sandboxes/{sandbox_id}removes pod and service
Prerequisites
Kubernetes Cluster
You need a running Kubernetes cluster. Supported options:- Docker Desktop with Kubernetes enabled
- OrbStack (macOS) with built-in K8s
- minikube for local development
- kind for local development
- k3s for lightweight production
- Cloud providers: EKS, GKE, AKS
Enable Kubernetes in Docker Desktop
- Open Docker Desktop settings
- Go to “Kubernetes” tab
- Check “Enable Kubernetes”
- Click “Apply & Restart”
- Wait for Kubernetes to start (green indicator)
Enable Kubernetes in OrbStack
- Open OrbStack settings
- Go to “Kubernetes” tab
- Check “Enable Kubernetes”
Verify Cluster
Configuration
1. Configure Sandbox Mode
Editconfig.yaml to enable provisioner mode:
2. Set Environment Variables
Editdocker/docker-compose-dev.yaml to configure provisioner:
3. Set Host Paths
Important:SKILLS_HOST_PATH and THREADS_HOST_PATH must be absolute paths on your host machine:
Provisioner Service
Docker Compose Configuration
The provisioner service is defined indocker/docker-compose-dev.yaml:
Provisioner Dockerfile
Fromdocker/provisioner/Dockerfile:
Deployment
Start with Provisioner
Verify Provisioner
Verify Namespace
Sandbox Pod Configuration
Pod Specification
Each sandbox runs as a Kubernetes Pod with:Service Specification
Each sandbox gets a NodePort service:API Reference
Health Check
Create Sandbox
Pending- Pod is being createdRunning- Pod is readySucceeded- Pod completed successfullyFailed- Pod failed to startUnknown- Status cannot be determined
Get Sandbox Status
List Sandboxes
Delete Sandbox
Testing
Manual Testing
Integration Testing
Test through the DeerFlow application:- Open http://localhost:2026
- Create a new thread
- Send a message that requires code execution (e.g., “Create a Python script”)
- Monitor pod creation:
- Check sandbox logs:
Troubleshooting
Kubeconfig Not Found
Symptom:Kubeconfig not found at /root/.kube/config
Solution:
Connection Refused to K8s API
Symptom:Connection refused when connecting to Kubernetes API
Solution:
-
Check kubeconfig server address:
-
If it’s
localhostor127.0.0.1, setK8S_API_SERVER: -
For Docker Desktop, the port is usually
6443 - For k3s/OrbStack, check the actual port
Invalid HostPath
Symptom:Unprocessable Entity when creating pod
Solution:
-
Use absolute paths only:
-
Verify paths exist:
Pod Stuck in ContainerCreating
Symptom: Pod stays inContainerCreating state
Diagnosis:
- Pulling sandbox image (wait or pre-pull with
make docker-init) - HostPath volume not accessible
- Insufficient resources on node
Cannot Access Sandbox URL
Symptom: Backend cannot reachhttp://host.docker.internal:{NodePort}
Solution:
-
Verify service exists:
-
Test from host:
-
Check
extra_hostsin docker-compose (Linux only): -
Verify
NODE_HOSTenvironment variable
Production Considerations
Resource Limits
Adjust pod resource limits based on workload:Persistent Storage
For production, consider using PersistentVolumes instead of HostPath:Network Policies
Restrict sandbox network access:Automatic Cleanup
Implement TTL for stale sandboxes:Monitoring
Integrate with Prometheus:Next Steps
Production Deployment
Production best practices and optimization
Docker Deployment
Learn about Docker-based deployment
See Also
- Sandbox Configuration - Configure sandbox modes
- Provisioner README - Detailed provisioner documentation
- Kubernetes Documentation - Official Kubernetes docs