Installation
- npm
- pnpm
- yarn
Quick Start
Core Features
Lifecycle Management
Manage the sandbox lifecycle, including renewal, pausing, and resuming.Custom Health Check
Define custom logic to determine whether the sandbox is ready/healthy. This overrides the default ping check used during readiness checks.Command Execution & Streaming
Execute commands and handle output streams in real-time.File Operations
Manage files and directories, including read, write, list/search, and delete.Endpoints
getEndpoint() returns an endpoint without a scheme (for example "localhost:44772"). Use getEndpointUrl() if you want a ready-to-use absolute URL (for example "http://localhost:44772").
Sandbox Management (Admin)
UseSandboxManager for administrative tasks and finding existing sandboxes.
Configuration
Connection Configuration
TheConnectionConfig class manages API server connection settings.
Runtime notes:
- In browsers, the SDK uses the global
fetchimplementation. - In Node.js, every
SandboxandSandboxManagerclones the baseConnectionConfigviawithTransportIfMissing(), so each instance gets an isolatedundicikeep-alive pool. Callsandbox.close()ormanager.close()when you are done so the SDK can release the associated agent.
| Parameter | Description | Default | Environment Variable |
|---|---|---|---|
apiKey | API key for authentication | Optional | OPEN_SANDBOX_API_KEY |
domain | Sandbox service domain (host[:port]) | localhost:8080 | OPEN_SANDBOX_DOMAIN |
protocol | HTTP protocol (http/https) | http | - |
requestTimeoutSeconds | Request timeout applied to SDK HTTP calls | 30 | - |
debug | Enable basic HTTP debug logging | false | - |
headers | Extra headers applied to every request | {} | - |
useServerProxy | Use sandbox server as proxy for execd/endpoint requests | false | - |
- Basic
- Advanced
Sandbox Creation Configuration
Sandbox.create() allows configuring the sandbox environment.
| Parameter | Description | Default |
|---|---|---|
image | Docker image to use | Required |
timeoutSeconds | Automatic termination timeout (server-side TTL) | 10 minutes |
entrypoint | Container entrypoint command | ["tail","-f","/dev/null"] |
resource | CPU and memory limits (string map) | {"cpu":"1","memory":"2Gi"} |
env | Environment variables | {} |
metadata | Custom metadata tags | {} |
networkPolicy | Optional outbound network policy (egress) | - |
extensions | Extra server-defined fields | {} |
skipHealthCheck | Skip readiness checks (Running + health check) | false |
healthCheck | Custom readiness check | - |
readyTimeoutSeconds | Max time to wait for readiness | 30 seconds |
healthCheckPollingInterval | Poll interval while waiting (milliseconds) | 200 ms |
Resource Cleanup
BothSandbox and SandboxManager own a scoped HTTP agent when running on Node.js so you can safely reuse the same ConnectionConfig. Once you are finished interacting with the sandbox or administration APIs, call sandbox.close() / manager.close() to release the underlying agent.
Browser Notes
- The SDK can run in browsers, but streaming file uploads are Node-only.
- If you pass
ReadableStreamorAsyncIterableforwriteFiles, the browser will fall back to buffering in memory before upload. - Reason: browsers do not support streaming
multipart/form-databodies with custom boundaries (required by the execd upload API).
API Reference
Sandbox
Main class for interacting with sandboxes.
Methods
Creates and initializes a new sandbox instance.Parameters:
connectionConfig(ConnectionConfig): Connection configurationimage(string): Docker image to usetimeoutSeconds(number, optional): Sandbox lifetime in secondsentrypoint(string[], optional): Custom entrypointresource(object, optional): CPU/memory limitsenv(object, optional): Environment variablesmetadata(object, optional): Custom metadatanetworkPolicy(NetworkPolicy, optional): Network egress ruleshealthCheck(function, optional): Custom health check functionreadyTimeoutSeconds(number, optional): Readiness timeout
Promise<Sandbox>Access to command execution operations.Returns:
CommandsClientAccess to file system operations.Returns:
FilesClientExtends the sandbox expiration time.Parameters:
timeoutSeconds(number): Extension duration in seconds
Promise<void>Pauses the sandbox (suspends all processes).Returns:
Promise<void>Resumes this paused sandbox.Returns:
Promise<Sandbox>Terminates the sandbox immediately.Returns:
Promise<void>Retrieves current sandbox information.Returns:
Promise<SandboxInfo>Gets the external endpoint for a port (without scheme).Parameters:
port(number): Internal port number
Promise<SandboxEndpoint>Gets the full URL for a port (with scheme).Parameters:
port(number): Internal port number
Promise<string>Releases the underlying HTTP agent (Node.js only).Returns:
Promise<void>Examples
Running a Node.js Script
Network Policy Example
Port Forwarding
Error Handling
TypeScript Support
The SDK is written in TypeScript and provides full type definitions.Next Steps
Python SDK
Explore the Python SDK
API Reference
Detailed API documentation
Examples
Browse more code examples
Configuration
Advanced configuration options