Create and manage isolated cloud sandboxes for secure code execution.
Register at ScaleBox Dashboard to get your API key.
Set environment variable:
export SCALEBOX_API_KEY="your-api-key-here"
Download the official CLI from ScaleBox Documentation:
# Visit official docs for platform-specific downloads
# https://www.scalebox.dev/docs/en/cli/installation
# After installation, authenticate:
scalebox-cli auth login --api-key $SCALEBOX_API_KEY --server-url https://api.scalebox.dev
Security Note: Always download CLI from official sources. Verify checksums when available.
https://api.scalebox.dev
Important: ScaleBox uses port prefixes, not port suffixes.
Use API to specify custom_ports when creating the sandbox:
curl -X POST "https://api.scalebox.dev/v1/sandboxes" \
-H "X-API-Key: $SCALEBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"template": "base",
"name": "my-sandbox",
"timeout": 3600,
"custom_ports": [
{"port": 8080, "name": "web-server", "protocol": "TCP"}
]
}'
If you need to add a port after creation:
# CLI
scalebox-cli sandbox port add <sandbox-id> --port 8080 --name web-server --protocol TCP
# API
curl -X POST "https://api.scalebox.dev/v1/sandboxes/{sandbox_id}/ports" \
-H "X-API-Key: $SCALEBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"port": 8080, "name": "web-server", "protocol": "TCP"}'
Format: https://{port}-{sandbox_domain}/path
Example:
sbx-abc123.k27xn5o3lnw5dan3x.scalebox.devhttps://8080-sbx-abc123.k27xn5o3lnw5dan3x.scalebox.dev/https://sbx-abc123.k27xn5o3lnw5dan3x.scalebox.dev:8080/| Template | CPU | Memory | Use Case |
|---|---|---|---|
| ---------- | ----- | -------- | ---------- |
| base | 2 | 512MB | Basic sandbox |
| code-interpreter | 2 | 1GB | Jupyter environment |
| browser-use | 2 | 2GB | Browser automation (VNC) |
| browser-use-headless | 4 | 4GB | Browser automation (headless) |
| desktop | 8 | 8GB | Desktop environment (VNC) |
| computer-use-preview | 2 | 2GB | Google Computer Use |
| Method | Best For | Notes |
|---|---|---|
| -------- | ---------- | ------- |
| CLI | File operations, command execution | Most powerful, cross-platform |
| REST API | Lifecycle management | Auth via X-API-Key header |
| Python SDK | Programmatic access | pip install scalebox-sdk |
# Create sandbox
scalebox-cli sandbox create --template <name> --name <name> --timeout <seconds>
# List sandboxes
scalebox-cli sandbox list
# Get sandbox details
scalebox-cli sandbox get <sandbox-id>
# Pause sandbox (preserves state)
scalebox-cli sandbox pause <sandbox-id>
# Resume paused sandbox
scalebox-cli sandbox resume <sandbox-id>
# Terminate sandbox immediately
scalebox-cli sandbox terminate <sandbox-id>
# Delete sandbox and resources
scalebox-cli sandbox delete <sandbox-id>
Create parameters:
--template: Template name or ID (default: base)--name: Sandbox name (optional, auto-generated)--timeout: Timeout in seconds (default: 300)--cpu: CPU count (minimum: 2)--memory: Memory in MB--storage: Storage in GB--async: Fire-and-forget mode - returns immediately, sandbox may still be starting. You must poll status yourself.--auto-pause: Pause on timeout instead of terminateImportant: async vs sync:
--async): Waits for sandbox to be fully running before returning. The returned sandbox is ready to use.--async): Returns immediately after creating the request. The sandbox may still be starting. You must poll sandbox get until status: running before using it.# Sync mode (recommended) - sandbox is ready when command returns
scalebox-cli sandbox create --template base --timeout 600
# Output includes sandbox ID, ready to use
# Async mode - need to wait
scalebox-cli sandbox create --template base --timeout 600 --async
# Returns immediately, sandbox may still be starting
# Must poll: scalebox-cli sandbox get <id> until status is "running"
# Upload file
scalebox-cli sandbox upload <sandbox-id> <local-path> <remote-path>
# Upload directory recursively
scalebox-cli sandbox upload <sandbox-id> ./project /workspace/project --recursive
# Download file
scalebox-cli sandbox download <sandbox-id> <remote-path> <local-path>
# List files
scalebox-cli sandbox ls <sandbox-id> <remote-path>
Note: Remote path must be absolute (e.g., /workspace/file.py).
# Execute command
scalebox-cli sandbox exec <sandbox-id> "<command>"
# With working directory
scalebox-cli sandbox exec <sandbox-id> "python3 script.py" --cwd /workspace
# With timeout
scalebox-cli sandbox exec <sandbox-id> "npm install" --timeout 120
All requests require X-API-Key header:
curl -H "X-API-Key: $SCALEBOX_API_KEY" https://api.scalebox.dev/v1/sandboxes
| Operation | Method | Endpoint |
|---|---|---|
| ----------- | -------- | ---------- |
| Create sandbox | POST | /v1/sandboxes |
| List sandboxes | GET | /v1/sandboxes |
| Get sandbox | GET | /v1/sandboxes/{id} |
| Delete sandbox | DELETE | /v1/sandboxes/{id} |
| Pause sandbox | POST | /v1/sandboxes/{id}/pause |
| Resume sandbox | POST | /v1/sandboxes/{id}/resume |
Note: File operations (upload/download/exec) are only available via CLI or SDK.
# Create sandbox
curl -X POST "https://api.scalebox.dev/v1/sandboxes" \
-H "X-API-Key: $SCALEBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"template": "base", "name": "my-sandbox", "timeout": 600}'
pip install scalebox-sdk
Module name: scalebox (not scalebox_sdk)
import scalebox
import os
# Create sandbox
sandbox = scalebox.Sandbox.create(
template="base",
timeout=600,
api_key=os.environ.get("SCALEBOX_API_KEY")
)
print(f"Sandbox ID: {sandbox.sandbox_id}")
# Get signed URLs for file operations
upload_url = sandbox.upload_url(path="/workspace/test.py")
download_url = sandbox.download_url(path="/workspace/output.json")
# Kill sandbox
sandbox.kill()
# 1. Create sandbox
sandbox_id=$(scalebox-cli sandbox create --template code-interpreter --name my-task --async | grep "Sandbox ID:" | awk '{print $3}')
# 2. Upload code
scalebox-cli sandbox upload $sandbox_id ./script.py /workspace/script.py
# 3. Execute
scalebox-cli sandbox exec $sandbox_id "python3 /workspace/script.py"
# 4. Download results
scalebox-cli sandbox download $sandbox_id /workspace/output.json ./output.json
# 5. Cleanup
scalebox-cli sandbox delete $sandbox_id
.. traversal)--internet=false)| Error | Solution |
|---|---|
| ------- | ---------- |
CPU count must be at least 2 | Use --cpu 2 or higher |
health check timeout | Check status with sandbox get |
Sandbox not found | Verify sandbox ID |
Timeout exceeded | Create new sandbox |
Last updated: 2026-03-21
共 1 个版本