ScaleBox Docs

Sandbox API

Complete API reference for managing sandbox environments. Sandboxes are isolated development environments that you can create, configure, and manage through the ScaleBox API.

Authentication: Most sandbox APIs require the X-API-Key header.

Exception: GET /v1/scalebox-regions is public (key optional). Use it to list region ids before setting locality.region on create.

Scalebox Regions (Discovery)

Call GET /v1/scalebox-regions to obtain id / name pairs for regions that currently have eligible capacity. Those ids are what you pass in locality.region when creating a sandbox. The same ids are validated against the global locality catalog; unknown regions return 400.

Sandbox Statuses

The sandbox status indicates its current lifecycle state:

StatusDescription
createdSandbox has been created but not started
startingSandbox is being started and resources are being allocated (substatus: allocating, deploying, initializing, waiting_ready)
runningSandbox is running and accessible
terminatingSandbox is being terminated and resources are being cleaned up (substatus: cleaning_resources, cleaning_data)
terminatedSandbox has been terminated and cannot be restarted
failedSandbox encountered an error during creation or operation

API Endpoints

Create Sandbox

POST /v1/sandboxes

Create a new sandbox. Default (sync): wait until running or failed. Set is_async: true to return immediately and poll status.

Request Parameters

NameTypeRequiredDefaultDescription
namestringNoAuto-generatedHuman-readable sandbox name (0-24 characters)
descriptionstringNoEmptyDetailed description of the sandbox purpose
templatestringNo"base"Template name or ID (e.g., "python-dev" or "tpl-abc123")
project_idstringNoUser's defaultProject to associate the sandbox with
cpu_countintegerNoTemplate defaultNumber of CPU cores
memory_mbintegerNoTemplate defaultMemory allocation in megabytes
storage_gbintegerNo50% of plan maxPersistent storage in gigabytes
timeoutintegerNo300Sandbox timeout in seconds
env_varsobjectNoEnvironment variables to set in the sandbox
metadataobjectNoCustom key-value pairs for sandbox metadata
securebooleanNotrueSecurity setting for the sandbox
allow_internet_accessbooleanNotrueWhether to allow internet access from the sandbox
object_storageobject/arrayNonullOne mount (JSON object) or multiple mounts (JSON array)
object_storage_direct_mountbooleanNofalseCustom templates only: mount object storage in the worker container
s3fs_executable_pathstringNoEmptyWhen using direct mount: optional path to the s3fs binary
custom_portsarrayNo[]Array of custom port configurations
localityobjectNonullOptional scheduling: { auto_detect: true } and/or { region: string, force?: boolean }
auto_pausebooleanNofalseWhen true, sandbox timeout triggers auto-pause instead of termination
is_asyncbooleanNofalseWhen true, return immediately (client polls for status)

Example

curl -X POST https://api.scalebox.dev/v1/sandboxes \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-dev",
    "template": "python-dev",
    "cpu_count": 2,
    "memory_mb": 4096,
    "storage_gb": 10,
    "timeout": 3600,
    "auto_pause": true,
    "is_async": false,
    "env_vars": {
      "DEBUG": "true",
      "API_KEY": "your-secret-key"
    },
    "metadata": {
      "project": "web-app",
      "environment": "development"
    },
    "object_storage": {
      "uri": "s3://my-bucket/data",
      "mount_point": "/mnt/oss",
      "access_key": "YOUR_S3_ACCESS_KEY",
      "secret_key": "YOUR_S3_SECRET_KEY",
      "region": "us-east-1"
    },
    "custom_ports": [
      { "port": 8080, "name": "web-server", "protocol": "tcp" },
      { "port": 9000, "name": "api-server", "protocol": "tcp" }
    ],
    "locality": {
      "region": "ap-southeast",
      "force": false
    }
  }'

List Scalebox Regions

GET /v1/scalebox-regions

Public discovery: Scalebox region ids that currently have at least one eligible cluster.

Example

curl -X GET https://api.scalebox.dev/v1/scalebox-regions

List Sandboxes

GET /v1/sandboxes

List all sandboxes for the authenticated user.

Example

curl -X GET https://api.scalebox.dev/v1/sandboxes \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Get Sandbox

GET /v1/sandboxes/{sandbox_id}

Get detailed information about a specific sandbox.

Example

curl -X GET https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789 \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Update Sandbox

PUT /v1/sandboxes/{sandbox_id}

Update sandbox configuration (extend timeout only).

Request Parameters

NameTypeRequiredDescription
timeoutintegerYesNew timeout in seconds (must be greater than current timeout)

Example

curl -X PUT https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789 \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{"timeout": 7200}'

Delete Sandbox

DELETE /v1/sandboxes/{sandbox_id}

Delete a sandbox and all associated resources.

Example

curl -X DELETE https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789 \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Pause Sandbox

POST /v1/sandboxes/{sandbox_id}/pause

Pause a running sandbox. Default (sync): wait until paused or rollback to running.

Request Parameters

NameTypeRequiredDefaultDescription
is_asyncbooleanNofalseWhen true, return immediately (client polls)

Example

curl -X POST https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789/pause \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{"is_async": false}'

Resume Sandbox

POST /v1/sandboxes/{sandbox_id}/resume

Resume a paused sandbox. Default (sync): wait until running or rollback to paused.

Request Parameters

NameTypeRequiredDefaultDescription
is_asyncbooleanNofalseWhen true, return immediately (client polls)

Example

curl -X POST https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789/resume \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{"is_async": false}'

Terminate Sandbox

POST /v1/sandboxes/{sandbox_id}/terminate

Force terminate a sandbox immediately.

Example

curl -X POST https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789/terminate \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678"

Batch Delete

POST /v1/sandboxes/batch-delete

Delete multiple sandboxes in batch.

Request Parameters

NameTypeRequiredDefaultDescription
sandbox_idsarrayYes-Array of sandbox IDs to delete (max 100)
forcebooleanNofalseForce delete even if running

Example

curl -X POST https://api.scalebox.dev/v1/sandboxes/batch-delete \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{
    "sandbox_ids": ["sbx-abc123def456789", "sbx-def456ghi789012"],
    "force": false
  }'

Batch Terminate

POST /v1/sandboxes/batch-terminate

Terminate multiple sandboxes concurrently (up to 50 processed simultaneously).

Request Parameters

NameTypeRequiredDefaultDescription
sandbox_idsarrayYes-Array of sandbox IDs to terminate (max 100)
forcebooleanNofalseForce terminate even if in transitional states

Batch Pause

POST /v1/sandboxes/batch-pause

Pause multiple running sandboxes concurrently.

Request Parameters

NameTypeRequiredDescription
sandbox_idsarrayYesArray of sandbox IDs to pause (max 100)

Batch Resume

POST /v1/sandboxes/batch-resume

Resume multiple paused sandboxes concurrently with budget and subscription validation.

Request Parameters

NameTypeRequiredDescription
sandbox_idsarrayYesArray of sandbox IDs to resume (max 100)

Update Timeout

POST /v1/sandboxes/{sandbox_id}/timeout

Update sandbox timeout independently.

Request Parameters

NameTypeRequiredDescription
timeoutintegerYesNew timeout in seconds

Example

curl -X POST https://api.scalebox.dev/v1/sandboxes/sbx-abc123def456789/timeout \
  -H "X-API-Key: sk-1234567890abcdef1234567890abcdef12345678" \
  -H "Content-Type: application/json" \
  -d '{"timeout": 7200}'

Switch Project

POST /v1/sandboxes/{sandbox_id}/switch-project

Move a sandbox to a different project.

Request Parameters

NameTypeRequiredDescription
project_idstringYesTarget project ID to move the sandbox to

Get Metrics

GET /v1/sandboxes/{sandbox_id}/metrics

Get raw sandbox performance metrics with time-series data.

Request Parameters

NameTypeRequiredDefaultDescription
startstringNo5 minutes agoStart time in ISO 8601, RFC3339, or Unix timestamp format
endstringNonowEnd time in ISO 8601, RFC3339, or Unix timestamp format
stepintegerNo5Time step in seconds between data points

Get Metrics Chart

GET /v1/sandboxes/{sandbox_id}/metrics/chart

Get chart-optimized metrics data for frontend visualization.

Request Parameters

NameTypeRequiredDefaultDescription
startstringNo5 minutes agoStart time
endstringNonowEnd time
stepstringNo5sTime step as duration string (e.g., '15m', '5s', '1h')

Get Stats

GET /v1/sandboxes/stats

Get sandbox statistics and usage data.

Create Template from Sandbox

POST /v1/sandboxes/{sandbox_id}/create-template

Create a template from a running sandbox. The sandbox must be in 'running' state.

Request Parameters

NameTypeRequiredDescription
namestringYesTemplate name (4-32 characters)
descriptionstringNoDetailed description of the template
visibilitystringNoTemplate visibility: 'private', 'account_shared', or 'public'
cpu_countintegerNoDefault CPU cores (nil/omit = inherit)
memory_mbintegerNoDefault memory in MB (nil/omit = inherit)
portsstringNoJSON array of additional port configurations
custom_commandstringNoCustom start command for the template
ready_commandstringNoReadiness probe JSON

Get Sandbox Ports

GET /v1/sandboxes/{sandbox_id}/ports

Get all ports for a sandbox (template ports + custom ports).

Add Sandbox Port

POST /v1/sandboxes/{sandbox_id}/ports

Add a custom port to a running sandbox.

Request Parameters

NameTypeRequiredDefaultDescription
portintegerYes-Port number (1-65535)
namestringYes-Port name (must be unique, max 15 characters)
protocolstringNoTCPProtocol (TCP, UDP, or WEBRTC)
service_portintegerNoSame as portService port number

Remove Sandbox Port

DELETE /v1/sandboxes/{sandbox_id}/ports/{port}

Remove a custom port from a running sandbox.

Get WebRTC TURN Credential

GET /v1/sandboxes/{sandbox_id}/webrtc-turn-credential

Get short-lived TURN credentials for a sandbox. The sandbox must be running and have at least one WebRTC port.

Object Storage

ScaleBox supports mounting S3-compatible object storage into sandboxes using FUSE. You can configure object storage at sandbox creation time, or mount it manually at runtime.

Object Storage Configuration

FieldTypeRequiredDescription
uristringYesS3-compatible storage URI: s3://bucket-name/path or oss://bucket-name/path
mount_pointstringYesAbsolute path in the container where the storage will be mounted
access_keystringYesS3 access key ID. Credentials are never stored or returned
secret_keystringYesS3 secret access key. Credentials are never stored or returned
regionstringNoS3 region string (e.g., us-east-1). At least one of region or endpoint required
endpointstringNoCustom S3-compatible endpoint URL

Manual Mounting at Runtime

All sandboxes have FUSE capabilities enabled. You can manually mount object storage:

# Create credentials file
echo "ACCESS_KEY:SECRET_KEY" > /root/.s3fs-credentials
chmod 600 /root/.s3fs-credentials

# Create mount point
mkdir -p /mnt/oss

# Mount S3 bucket
s3fs bucket-name:/path /mnt/oss \
  -o passwd_file=/root/.s3fs-credentials \
  -o url=https://s3.region.amazonaws.com \
  -o endpoint=region

Security Note: Object storage credentials are never persisted in the database. Only the URI and mount point are stored and returned in API responses.

Metrics API

The sandbox metrics API provides real-time performance data and historical trends for monitoring resource utilization.

Metrics Endpoints

Raw Metrics: /v1/sandboxes/{sandbox_id}/metrics

  • Returns standardized time-series metrics optimized for API consumers
  • Data Format: Array of timestamped metrics with CPU, memory, and disk usage
  • Use Cases: Monitoring, alerting, data analysis, integration with external tools

Chart Metrics: /v1/sandboxes/{sandbox_id}/metrics/chart

  • Returns chart-ready data optimized for frontend visualization
  • Features: Built-in statistics, trend analysis, color schemes, and chart configuration
  • Use Cases: Dashboard widgets, real-time monitoring, performance analytics

Time Parameters

ParameterDescription
startStart time for the metrics query. Supports ISO 8601, RFC3339, and Unix timestamp
endEnd time for the metrics query. Defaults to current time
stepTime interval between data points. Raw: seconds, Chart: duration string ('15m', '5s')

Resource Metrics

MetricDescription
CPURequested cores (integer) and usage percentage (0-100)
MemoryRequested and used memory in bytes
StorageRequested and used disk space in bytes
UptimeSandbox running time in seconds

Error Handling

ScenarioDescription
No Data AvailableReturns empty metrics array with status when sandbox is not running
Invalid Time RangeAutomatically swaps start/end times if they're in wrong order
Resource Not FoundReturns 404 if sandbox doesn't exist or user lacks access

Best Practices

PracticeDescription
Time Range SelectionUse appropriate step sizes: 5-30 seconds for real-time, 1-15 minutes for historical
Data PollingPoll metrics every 30-60 seconds for live dashboards
Error HandlingAlways check the response status and handle cases where metrics data is unavailable

HTTP Status Codes

CodeDescription
200Success
201Created
400Bad Request
401Unauthorized
403Forbidden
404Not Found
429Too Many Requests
500Internal Server Error

On this page