Skip to main content

StateSet Sandbox - Production Guide

Overview

StateSet Sandbox is a secure, isolated execution environment for running code on behalf of AI agents. It provides containerized sandboxes with full lifecycle management, checkpointing, artifact storage, and usage tracking.

Architecture

Component Details

Exec Agent Runtime

The sandbox base image includes both Node.js and Go exec agents. Set EXEC_AGENT_RUNTIME=go for a lower memory footprint (~8 MB vs ~45 MB RSS). The two runtimes are wire-compatible, so no controller changes are needed.

Database Tables


User Flow

1. Registration

Developer signs up via API or dashboard:
Response:

2. SDK Installation

Node.js:
Python:
Additional preview SDKs are available in this repo:
  • Rust: sdk-rust/README.md
  • Ruby: sdk-ruby/README.md
  • Go: sdk-go/README.md
  • PHP: sdk-php/README.md
  • Java: sdk-java/README.md
  • Kotlin: sdk-kotlin/README.md
  • Swift: sdk-swift/README.md

3. Basic Usage

Advanced endpoints (checkpoints, artifacts, webhooks, templates) are available via StateSetSandboxExtended:

4. Advanced: Checkpoints

Save and restore sandbox state:

5. Advanced: Artifacts

Upload and download files:

6. Advanced: Webhooks

Get notified of sandbox events:
Webhook Payload:
Signature Verification:

7. Templates

Create sandboxes from pre-configured templates:
Available Templates:

8. REPL Sessions

Interactive Python REPL with persistent session state. Variables, imports, and objects survive across execute calls — ideal for data exploration, iterative development, and AI agent workflows. Enable: Set REPL_ENABLED=true on the controller.

API Reference

Authentication

All API requests require authentication via header:
The organization is inferred from the API key or JWT claims; no org header is required. Or with JWT:

Endpoints

Registration & API Keys

Sandboxes

Checkpoints

Artifacts

Webhooks

Usage & Billing

Templates

REPL Sessions


Webhook Events


Pricing

Plans

Usage-Based Pricing


Dashboard

Access at: https://sandbox.stateset.com/dashboard

Pages


Security

API Key Security

  • Keys are hashed (SHA-256) before storage
  • Original key shown only once at creation
  • Keys can have scopes and expiration
  • Rate limiting per key

Sandbox Isolation

  • Each sandbox runs in isolated Kubernetes pod
  • Network policies restrict pod communication
  • Resource limits enforced (CPU, memory)
  • Read-only root filesystem
  • Non-root user execution

Data Protection

  • All data encrypted in transit (TLS)
  • Database encrypted at rest
  • Secrets stored encrypted with KMS
  • Audit logging for compliance

Environment Variables

Controller Configuration


Metrics Access

/metrics is protected in production. Configure your monitoring stack to include the auth header you use for metrics access. If you use Prometheus Operator, apply k8s/prometheus/service-monitor.yaml and add your metrics auth header to the scrape config:
If you keep network policies enabled, label the monitoring namespace to allow scraping:

Warm Pool Profiles

Use warm pool profiles to pre‑warm the most common CPU/memory shapes and reduce cold starts. Profiles are matched on cpus + memory with optional isolation. Example configuration:
If you pass isolation on sandbox creation, ensure the matching warm pool profile sets the same isolation. Internal stats endpoint (production requires X-Internal-Token):

Tunnel Configuration

Tunnels expose a sandbox port through the API gateway. Optional settings:
  • TUNNEL_BASE_URL=https://api.sandbox.yourdomain.com
  • TUNNEL_DEFAULT_TTL_SECONDS=3600
  • TUNNEL_MAX_TTL_SECONDS=86400

Artifact Storage (Cloud)

Google Cloud Storage (GCS)

Required settings:
  • STORAGE_PROVIDER=gcs
  • STORAGE_BUCKET=your-bucket
remote_path is treated as a relative path and always stored under artifacts/<organization-id>/. If you are not using Workload Identity, mount a service account key and set:
  • GCS_PROJECT_ID=your-gcp-project-id
  • GCS_KEY_FILE=/var/secrets/gcp/key.json
Example secret creation:
Mount the secret and set env vars in your controller deployment:
Verify artifacts end-to-end:

Deployment

Kubernetes Resources

Custom Resource Definitions (CRDs)

Apply CRDs before deploying:
Optional: Set SANDBOX_BACKEND=crd for declarative sandbox management. This enables kubectl get ssb (sandboxes) and kubectl get wp (warm pool entries).

Health Checks

  • Liveness: GET /health
  • Readiness: GET /ready

Troubleshooting

Common Issues

401 Unauthorized
  • Check API key format: ApiKey sk-sandbox-xxx
  • Verify key exists in the database and is not revoked
Sandbox Creation Failed
  • Check Kubernetes connectivity
  • Verify namespace exists
  • Check resource quotas
Database Connection Failed
  • Verify database proxy is running (if used)
  • Check workload identity / service account bindings
  • Verify database credentials

Logs


Support