API Reference
Python SDK
Static methods
| Method | Returns | Description |
|---|---|---|
| Sandbox.create(**kwargs) | Sandbox | Create a new sandbox. Waits for agent healthy before returning. |
| Sandbox.connect(id, **kwargs) | Sandbox | Connect to an existing sandbox by ID. |
| Sandbox.list(**kwargs) | list[Sandbox] | List sandboxes. Optional label filtering via labels= dict. |
| Sandbox.list_profiles() | list[Profile] | List available pre-defined profiles from the server. |
| Sandbox.get_system_stats() | SystemStats | Get server-level CPU/memory stats. |
Instance properties & methods
| Member | Type / Returns | Description |
|---|---|---|
| id | str | 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() | None | Destroy the sandbox |
| pause() | None | Pause the VM (freeze state in memory) |
| resume() | None | Resume a paused VM |
| is_running() | bool | Check if the sandbox is healthy |
| get_info() | SandboxInfo | Get metadata: id, template_id, status, started_at |
| set_timeout(ms) | None | Update the auto-destroy timeout |
| run_code(code, language, context) | ExecResult | Run code in a persistent REPL context (python, js, bash) |
| commit(ref) | dict | Save filesystem as a reusable image. Returns {id, ref, status}. |
| fork() | Sandbox | Create a copy of this sandbox |
| snapshot() | dict | Capture full VM state. Returns {snapshot_path, mem_file_path}. |
| get_stats() | dict | Current CPU, memory, disk, network usage |
| stream_stats(cb) | callable | Subscribe to real-time stats via SSE. Returns unsubscribe function. |
| get_metrics() | list[dict] | Legacy E2B-compatible metrics format |
| update_memory(mb) | None | Adjust VM memory via balloon device |
| apply_sandbox_file(yaml_str) | None | Apply a declarative Sandboxfile configuration |
| get_preview_url(port) | str | Get a shareable URL for a sandbox port |
| set_internet(enabled) | None | Toggle outbound internet access |
| exec_in_terminal(cmd) | None | Execute a command through the active PTY |
| on_event(cb) | callable | Subscribe to lifecycle events. Returns unsubscribe function. |
| stream_logs(cb) | callable | Subscribe to serial console logs. Returns unsubscribe function. |
CommandManager
| Method | Description |
|---|---|
| run(cmd, envs, background, on_stdout, on_stderr) | Execute a command. Returns ExecResult with stdout, stderr, exit_code, pid. |
FileManager
| Method | Description |
|---|---|
| read(path) | Read a text file |
| read_bytes(path) | Read a file as bytes |
| write(path, content) | Write text or bytes |
| list(path) | List directory contents with FileInfo entries |
| make_dir(path) | Create a directory |
| exists(path) | Check if a path exists |
| remove(path) | Delete a file or directory |
| rename(old_path, new_path) | Rename/move a file |
| watch(path, cb) | Watch a directory for changes. Returns unsubscribe function. |
| watch_multiplex(paths, cb) | Watch multiple directories over a single WebSocket |
| read_stream(path) | Read a file as a stream (async) |
| write_stream(path, stream) | Write from a stream (async) |
| upload_archive(data, remote_path) | Upload a tar archive and extract it |
| download_archive(remote_path) | Download a directory as a tar archive |
| upload_dir(files, remote_path) | Upload multiple files from a dict |
| download_dir(remote_path) | Download a directory as a dict of bytes |
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: author_name, author_email, allow_empty, files. |
| push(path, **opts) | Push to remote. Options: remote, branch, username, password, set_upstream. |
| pull(path, **opts) | Pull from remote. Options: remote, branch, username, password. |
| remote_add(path, name, url, **opts) | Add a remote. Options: fetch, overwrite. |
| branches(path) | List branches |
| create_branch(path, name) | Create a new branch |
| checkout_branch(path, name, **opts) | Checkout a branch. Options: force. |
| delete_branch(path, name) | Delete a branch |
| get_config(key, **opts) | Get a git config value. Options: scope, path. |
| set_config(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.exec_in_terminal(cmd) | Execute a command through the active PTY |
| terminal.get_session_id() | Get the current session ID |
| handle.write(data) | Write data to terminal stdin |
| handle.on_data(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, cmd |
| 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.wait_for_port(port, timeout_ms) | Wait for a port to be listening |
| ports.get_preview_url(port) | Get a shareable preview URL for a port |
ImageManager
| Method | Description |
|---|---|
| ImageManager(url) | Create an ImageManager instance for a server URL |
| img_mgr.convert(image_ref) | Convert a Docker/OCI image to MicroVM rootfs |
| img_mgr.build(context, tag, dockerfile) | Build from a tarball context |
| img_mgr.list() | List images |
| img_mgr.get(image_id) | Get image status |
| img_mgr.warm(image_id) | Pre-create VM snapshot for faster boot |
| img_mgr.delete(image_id) | Delete an image |
| img_mgr.list_templates() | List cached templates |
| img_mgr.upload_template(buffer, name) | Upload a template tarball |
| img_mgr.delete_template(name) | Delete a template |