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)
SANDBOX_RUNTIME_CLASS is applied to all sandbox pods:
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
-
Generate strong keys:
-
Use environment variables (never hardcode):
-
Rotate keys regularly:
-
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)
- Encrypted at rest in Postgres using AES-256-GCM (
DATABASE_ENCRYPTION_KEYis required in production whenDATABASE_URLis 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: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)
Custom Network Policies
Create Kubernetes NetworkPolicy for additional restrictions:Webhook URL Validation
Webhooks cannot target:- localhost
- Private IP addresses
- Cluster-internal services
- 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 viash -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: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: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: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_SECRETis unique, 32+ characters -
ADMIN_API_KEYis set and strong -
INTERNAL_API_KEYis set for metrics - API keys are rotated regularly
Database
-
DATABASE_ENCRYPTION_KEYis 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
- Identify: Check audit logs for anomalies
- Contain: Suspend affected organization
- Investigate: Review logs, metrics, sandbox contents
- Remediate: Revoke compromised keys, patch vulnerabilities
- Document: Post-incident report
Key Compromise
- Revoke the compromised key immediately
- Generate new keys
- Audit recent activity with the compromised key
- Notify affected users
- Review how the key was exposed
Data Breach Response
- Assess scope of breach
- Contain the breach (suspend orgs, terminate sandboxes)
- Notify affected parties per GDPR/regulatory requirements
- Document timeline and response
- 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
- Security issues: security@stateset.com
- Bug bounty: https://stateset.com/security/bounty
- Security documentation: https://stateset.com/security