Skip to content
GitHubRSS

Sandbox Management

Create, retrieve, list, and destroy sandboxes.

Create a new sandbox instance.

// With explicit provider
const sandbox = await compute.sandbox.create({
  provider: e2b({ apiKey: 'your-key' }),
  options: { runtime: 'python', timeout: 300000 }
});

// With default provider
const sandbox = await compute.sandbox.create({
  options: { runtime: 'python' }
});

Parameters:

  • options - Creation options
    • provider? - Specific provider to use (overrides global config)
    • options? - Provider-specific options
      • runtime? - Runtime environment (‘python’ | ‘node’)
      • timeout? - Execution timeout in milliseconds

Returns: Sandbox instance with unique sandboxId

Retrieve an existing sandbox by ID.

const sandbox = await compute.sandbox.getById('sandbox-id');

Parameters:

  • id - Sandbox ID string

Returns: Sandbox instance

List all active sandboxes.

const sandboxes = await compute.sandbox.list();
console.log(sandboxes.length); // Number of active sandboxes

Returns: Array of sandbox instances

Destroy a sandbox and clean up resources.

await compute.sandbox.destroy('sandbox-id');

// Or using sandbox instance
await compute.sandbox.destroy(sandbox.sandboxId);

Parameters:

  • id - Sandbox ID string

Returns: Promise that resolves when sandbox is destroyed

Once created, a sandbox instance provides methods for code execution, filesystem operations, and terminal management.

interface Sandbox {
  sandboxId: string;
  provider: string;
  
  runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
  runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
  
  filesystem: FilesystemAPI;
  terminal: TerminalAPI;
  
  getInfo(): Promise<SandboxInfo>;
}