Skip to main content

Security Best Practices Guide

This guide covers security considerations for deploying and using StateSet Sandbox, including isolation options, secret management, network policies, and compliance.

Security Architecture

Isolation Levels

Isolation is enforced at the Kubernetes pod level via RuntimeClass (and your cluster’s configured runtimes).
  • Container: default runtime (no RuntimeClass)
  • gVisor: a gVisor RuntimeClass (often named gvisor)
  • MicroVM: a Kata/Firecracker RuntimeClass (often named kata-qemu)
In the Node controller, SANDBOX_RUNTIME_CLASS is applied to all sandbox pods:
The sandbox create API accepts an isolation field (container | gvisor | microvm) which is currently used for warm pool profile matching and labeling; the actual isolation boundary is provided by the RuntimeClass.

API Key Security

Key Management

  1. Generate strong keys:
  2. Use environment variables (never hardcode):
  3. Rotate keys regularly:
  4. Use scoped keys when possible:
    • Read-only keys for monitoring
    • Limited keys for specific sandboxes

Key Storage

Secret Management

StateSet stores secrets at the organization level and injects them into sandbox pods as environment variables at creation time.

Create / Update Secrets (BYOK)

Security properties:
  • Encrypted at rest in Postgres using AES-256-GCM (DATABASE_ENCRYPTION_KEY is required in production when DATABASE_URL is set)
  • Never logged or returned by list endpoints
  • Persist until deleted (not tied to a single sandbox lifetime)
  • Can be restricted to specific sandboxes using allowed_sandbox_patterns

Secret Access Logging

Enable audit logging for secret access:
Query audit logs:

Network Security

Default Network Policy

In the provided Kubernetes manifests (k8s/network-policy.yaml), sandbox pods:
  • Allow ingress only from the controller
  • Allow egress only to:
    • DNS (kube-dns)
    • TCP 443 to a Cloudflare IP allowlist (to reach api.anthropic.com)
This is intentionally restrictive and IP-based (NetworkPolicy cannot match by DNS name). If you need broader egress or DNS-aware allowlisting, use an egress proxy/service mesh or a CNI with DNS-aware policies (e.g., Cilium).

Custom Network Policies

Create Kubernetes NetworkPolicy for additional restrictions:

Webhook URL Validation

Webhooks cannot target:
  • localhost
  • Private IP addresses
  • Cluster-internal services
Webhook requests:
  • Follow up to 3 redirects
  • Block cross-host redirects
  • Block HTTPS→HTTP downgrades

Input Validation

Path Traversal Prevention

All file paths are validated:
  • No .. components allowed
  • Must be within sandbox workspace
  • Absolute paths normalized

Command Injection Prevention

Prefer passing commands as arrays to avoid shell interpolation. If you send a string command, the controller executes it via sh -c.

Request Size Limits

Pod Security

Security Context

Sandbox pods run with restricted security context:

Service Account

Sandboxes use a dedicated service account without cluster access:
Configuration:

Resource Limits

All sandboxes have enforced limits:

Database Security

Encryption at Rest

Sensitive values stored in the database (e.g., organization secrets and webhook secrets) are encrypted with AES-256-GCM. API keys are stored as one-way hashes (not reversible); only prefixes are returned for display. Configuration:
Generate key:

Connection Security

Access Control

Use separate database users:
  • Application user with limited permissions
  • Migration user for schema changes
  • Read-only user for analytics

Authentication & Authorization

JWT Configuration

Admin Access

Protect admin endpoints:
Generate bcrypt hash:

Internal Endpoints

Protect internal endpoints (/metrics, /health/detailed):

Audit Logging

Enable Audit Logs

Logged Events

  • Sandbox creation/termination
  • Command execution
  • File operations
  • Secret access
  • API key operations
  • Admin actions

Log Format

Log Retention

Configure retention policy based on compliance requirements:
  • SOC2: 1 year minimum
  • HIPAA: 6 years
  • GDPR: Document justification for retention period

Production Hardening Checklist

Environment Configuration

  • NODE_ENV=production
  • DEV_MODE=false
  • LOG_LEVEL=info (not debug/trace)

Authentication

  • JWT_SECRET is unique, 32+ characters
  • ADMIN_API_KEY is set and strong
  • INTERNAL_API_KEY is set for metrics
  • API keys are rotated regularly

Database

  • DATABASE_ENCRYPTION_KEY is set (64 hex chars)
  • SSL enabled for database connection
  • Database credentials are from secret manager
  • Regular backups configured

Network

  • CORS restricted to your domains: CORS_ORIGIN=https://app.example.com
  • TLS/HTTPS enforced
  • WEBHOOK_ALLOW_PRIVATE=false
  • WS_ALLOW_QUERY_AUTH=false (legacy/deprecated; query-token auth is disabled for Events/WebSocket)

Sandbox Security

  • SANDBOX_READ_ONLY_ROOT=true
  • SANDBOX_AUTOMOUNT_SERVICE_ACCOUNT_TOKEN=false
  • SANDBOX_ENABLE_SERVICE_LINKS=false
  • Appropriate isolation level set
  • Resource limits configured

Monitoring

  • AUDIT_LOGS_ENABLED=true
  • Metrics collection configured
  • Alerting for security events
  • Log aggregation configured

Incident Response

Suspicious Activity

  1. Identify: Check audit logs for anomalies
  2. Contain: Suspend affected organization
  3. Investigate: Review logs, metrics, sandbox contents
  4. Remediate: Revoke compromised keys, patch vulnerabilities
  5. Document: Post-incident report

Key Compromise

  1. Revoke the compromised key immediately
  2. Generate new keys
  3. Audit recent activity with the compromised key
  4. Notify affected users
  5. Review how the key was exposed

Data Breach Response

  1. Assess scope of breach
  2. Contain the breach (suspend orgs, terminate sandboxes)
  3. Notify affected parties per GDPR/regulatory requirements
  4. Document timeline and response
  5. Improve security controls

Compliance Considerations

SOC2

  • Enable audit logging
  • Encrypt data at rest
  • Implement access controls
  • Monitor for anomalies
  • Document security policies

GDPR

  • Document data processing purposes
  • Implement data retention policies
  • Support data export and deletion
  • Log consent and access
  • Appoint DPO if required

HIPAA

  • Sign BAA with cloud providers
  • Enable audit logging
  • Encrypt all PHI
  • Implement access controls
  • Train staff on HIPAA

Security Contacts