API Reference
TypeScript SDK
Static methods
| Method | Returns | Description |
|---|---|---|
| Sandbox.create(opts?) | Promise<Sandbox> | Create a new sandbox. Waits for agent healthy before resolving. |
| Sandbox.connect(id, opts?) | Promise<Sandbox> | Connect to an existing sandbox by ID. |
| Sandbox.list(opts?) | Promise<Sandbox[]> | List sandboxes. Optional label filtering via opts.labels. |
| Sandbox.listProfiles() | Promise<Profile[]> | List available pre-defined profiles from the server. |
| Sandbox.getSystemStats() | Promise<SystemStats> | Get server-level CPU/memory stats. |
Instance properties & methods
| Member | Type / Returns | Description |
|---|---|---|
| id | string | Workspace ID |
| commands | CommandManager | Execute commands in the sandbox |
| files | FileManager | Read, write, list, watch files |
| git | GitManager | Clone, commit, push, pull, branch operations |
| terminal | TerminalManager | WebSocket PTY sessions |
| process | ProcessManager | List, kill, attach to processes |
| ports | PortManager | List ports, wait for services, preview URLs |
| close() | Promise<void> | Destroy the sandbox |
| pause() | Promise<void> | Pause the VM (freeze state in memory) |
| resume() | Promise<void> | Resume a paused VM |
| isRunning() | Promise<boolean> | Check if the sandbox is healthy |
| getInfo() | Promise<SandboxInfo> | Get metadata: ID, template, status, createdAt |
| setTimeout(ms) | Promise<void> | Update the auto-destroy timeout |
| runCode(code, opts?) | Promise<ExecResult> | Run code in a persistent REPL context (python, js, bash) |
| commit(ref?) | Promise<CommitResult> | Save filesystem as a reusable image |
| fork() | Promise<Sandbox> | Create a copy of this sandbox |
| snapshot() | Promise<SnapshotResult> | Capture full VM state (memory + disk) |
| getStats() | Promise<VMStats> | Current CPU, memory, disk, network usage |
| streamStats(cb) | () => void | Subscribe to real-time stats via SSE. Returns unsubscribe function. |
| getMetrics() | Promise<Metrics[]> | Legacy E2B-compatible metrics format |
| updateMemory(mb) | Promise<void> | Adjust VM memory via balloon device |
| applySandboxFile(yaml) | Promise<void> | Apply a declarative Sandboxfile configuration |
| getPreviewUrl(port) | Promise<string> | Get a shareable URL for a sandbox port |
| setInternet(enabled) | Promise<void> | Toggle outbound internet access |
| execInTerminal(cmd) | Promise<void> | Execute a command through the active PTY |
| onEvent(cb) | () => void | Subscribe to lifecycle events (starting, running, stopped, etc.) |
| streamLogs(cb) | () => void | Subscribe to serial console logs via WebSocket |
CommandManager
| Method | Description |
|---|---|
| run(cmd, opts?) | Execute a command. Options: envs, background, onStdout, onStderr, context. |
FileManager
| Method | Description |
|---|---|
| read(path) | Read a text file |
| write(path, content) | Write a text or binary (Uint8Array) file |
| list(path) | List directory contents with FileInfo entries |
| makeDir(path) | Create a directory |
| exists(path) | Check if a path exists |
| remove(path) | Delete a file or directory |
| rename(oldPath, newPath) | Rename/move a file |
| watch(path, cb) | Watch a directory for changes. Returns unsubscribe function. |
| watchMultiplex(paths, cb) | Watch multiple directories over a single WebSocket |
| readStream(path) | Read a file as a ReadableStream |
| writeStream(path, stream) | Write from a ReadableStream, Blob, ArrayBuffer, or string |
| uploadArchive(tarData, remotePath) | Upload a tar archive and extract it |
| downloadArchive(remotePath) | Download a directory as a tar archive (ReadableStream) |
| uploadDir(files, remotePath) | Upload multiple files at once from a Record<string, string|Uint8Array> |
| downloadDir(remotePath) | Download a directory as Record<string, Uint8Array> |
GitManager
| Method | Description |
|---|---|
| clone(url, opts?) | Clone a repository. Options: path, branch, depth, username, password. |
| status(path) | Get git status output |
| add(path, files?) | Stage files (all if files omitted) |
| commit(path, message, opts?) | Commit changes. Options: authorName, authorEmail, allowEmpty, files. |
| push(path, opts?) | Push to remote. Options: remote, branch, username, password, setUpstream. |
| pull(path, opts?) | Pull from remote. Options: remote, branch, username, password. |
| remoteAdd(path, name, url, opts?) | Add a remote. Options: fetch, overwrite. |
| branches(path) | List branches |
| createBranch(path, name) | Create a new branch |
| checkoutBranch(path, name, opts?) | Checkout a branch. Options: force. |
| deleteBranch(path, name) | Delete a branch |
| getConfig(key, opts?) | Get a git config value. Options: scope, path. |
| setConfig(key, value, opts?) | Set a git config value. Options: scope, path. |
TerminalManager & TerminalHandle
| Method | Description |
|---|---|
| terminal.connect() | Open a WebSocket PTY session. Returns TerminalHandle. |
| terminal.resize(cols, rows) | Resize the active PTY |
| terminal.execInTerminal(cmd) | Execute a command through the active PTY |
| terminal.getSessionId() | Get the current session ID |
| handle.write(data) | Write data to terminal stdin |
| handle.onData(cb) | Register callback for terminal output |
| handle.resize({cols, rows}) | Resize the PTY |
| handle.wait(timeout?) | Wait for session to end |
| handle.close() | Close the terminal session |
ProcessManager
| Method | Description |
|---|---|
| process.list() | List running processes with PID, PPID, CPU%, MEM%, command |
| process.kill(pid, signal?) | Kill a process. Signal defaults to SIGKILL. |
| process.attach(pid, cb) | Attach to a background process output stream. Returns unsubscribe. |
PortManager
| Method | Description |
|---|---|
| ports.list() | List open ports with protocol, state, and address |
| ports.waitForPort(port, timeoutMs?) | Wait for a port to be listening |
| ports.getPreviewUrl(port) | Get a shareable preview URL for a port |
ImageManager
| Method | Description |
|---|---|
| ImageManager.convert(imageRef) | Convert a Docker/OCI image to MicroVM rootfs |
| ImageManager.build(context, tag, dockerfile?) | Build from a tarball context |
| ImageManager.list() | List images |
| ImageManager.get(id) | Get image status |
| ImageManager.warm(id) | Pre-create VM snapshot for faster boot |
| ImageManager.delete(id) | Delete an image |
| ImageManager.listTemplates() | List cached templates |
| ImageManager.uploadTemplate(buffer, name) | Upload a template tarball |
| ImageManager.deleteTemplate(name) | Delete a template |