Overview
The SDK provides structured error handling with type-safe error classes, automatic retry logic for transient failures, and detailed error context for debugging.Error hierarchy
All SDK errors extendSandboxError and include structured context:
Error structure
Every error includes:code- Error code enum value (e.g.,FILE_NOT_FOUND)message- Human-readable error messagecontext- Type-safe context object with error detailshttpStatus- HTTP status code from container APIoperation- Operation that failed (e.g.,file.read)suggestion- Actionable suggestion to fix the errortimestamp- ISO 8601 timestamp when error occurreddocumentation- Link to relevant documentation (when available)
Error categories
File system errors
FileNotFoundError - File or directory doesn’t exist:Command errors
CommandNotFoundError - Command doesn’t exist:Process errors
ProcessNotFoundError - Process doesn’t exist:Port errors
PortAlreadyExposedError - Port is already exposed:Git errors
GitRepositoryNotFoundError - Repository doesn’t exist:Backup errors
BackupNotFoundError - Backup doesn’t exist in R2:Automatic retry logic
The SDK automatically retries transient failures when starting containers.HTTP status code semantics
| Status | Meaning | SDK Behavior |
|---|---|---|
| 503 | Service Unavailable (container starting) | Retry with exponential backoff |
| 500 | Internal Server Error (config error) | Fail immediately |
| 400 | Bad Request (capacity limits, validation) | Fail immediately |
Retry configuration
Default settings:- Total budget: 2 minutes
- Backoff: 3s → 6s → 12s → 24s → 30s (capped at 30s)
- Only retries: 503 errors
Customize retry behavior
Capacity limit errors
When hitting account limits, the Containers API returns 400 with error codes:Error codes
| Code | Description | Action |
|---|---|---|
SURPASSED_BASE_LIMITS | Exceeded per-deployment limits | Scale down or contact support |
SURPASSED_TOTAL_LIMITS | Exceeded account-wide limits | Call destroy() on unused sandboxes |
LOCATION_SURPASSED_BASE_LIMITS | Exceeded location-specific limits | Use different location or scale down |
Handling capacity errors
Account limits (Workers Paid)
Default limits for Workers Paid plan:| Resource | Limit |
|---|---|
| Concurrent Memory | 400 GiB |
| Concurrent vCPU | 100 |
| Concurrent Disk | 2 TB |