Skip to main content

AsyncCommandHandle

Command execution handle. It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.

pid

Command process ID.

stdout

Command stdout output.

stderr

Command stderr output.

error

Command execution error message.

exit_code

Command execution exit code. 0 if the command finished successfully. It is None if the command is still running.

disconnect

Disconnects from the command. The command is not killed, but SDK stops receiving events from the command. You can reconnect to the command using sandbox.commands.connect method.

wait

Wait for the command to finish and return the result. If the command exits with a non-zero exit code, it throws a CommandExitException. Returns: CommandResult result of command execution

kill

Kills the command. It uses SIGKILL signal to kill the command Returns: True if the command was killed successfully, False if the command was not found

Pty

Module for interacting with PTYs (pseudo-terminals) in the sandbox.

kill

Kill PTY. Arguments:
  • pid: Process ID of the PTY
  • request_timeout: Timeout for the request in seconds
Returns: true if the PTY was killed, false if the PTY was not found

send_stdin

Send input to a PTY. Arguments:
  • pid: Process ID of the PTY
  • data: Input data to send
  • request_timeout: Timeout for the request in seconds

create

Start a new PTY (pseudo-terminal). Arguments:
  • size: Size of the PTY
  • on_data: Callback to handle PTY data
  • user: User to use for the PTY
  • cwd: Working directory for the PTY
  • envs: Environment variables for the PTY
  • timeout: Timeout for the PTY in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Handle to interact with the PTY

connect

Connect to a running PTY. Arguments:
  • pid: Process ID of the PTY to connect to. You can get the list of running PTYs using sandbox.pty.list().
  • on_data: Callback to handle PTY data
  • timeout: Timeout for the PTY connection in seconds. Using 0 will not limit the connection time
  • request_timeout: Timeout for the request in seconds
Returns: Handle to interact with the PTY

resize

Resize PTY. Call this when the terminal window is resized and the number of columns and rows has changed. Arguments:
  • pid: Process ID of the PTY
  • size: New size of the PTY
  • request_timeout: Timeout for the request in seconds

Commands

Module for executing commands in the sandbox.

list

Lists all running commands and PTY sessions. Arguments:
  • request_timeout: Timeout for the request in seconds
Returns: List of running commands and PTY sessions

kill

Kill a running command specified by its process ID. It uses SIGKILL signal to kill the command. Arguments:
  • pid: Process ID of the command. You can get the list of processes using sandbox.commands.list()
  • request_timeout: Timeout for the request in seconds
Returns: True if the command was killed, False if the command was not found

send_stdin

Send data to command stdin. :param pid Process ID of the command. You can get the list of processes using sandbox.commands.list(). :param data: Data to send to the command :param request_timeout: Timeout for the request in seconds

run

Start a new command and wait until it finishes executing. Arguments:
  • cmd: Command to execute
  • background: False if the command should be executed in the foreground, True if the command should be executed in the background
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • on_stdout: Callback for command stdout output
  • on_stderr: Callback for command stderr output
  • stdin: If True, the command will have a stdin stream that you can send data to using sandbox.commands.send_stdin()
  • timeout: Timeout for the command connection in seconds. Using 0 will not limit the command connection time
  • request_timeout: Timeout for the request in seconds
Returns: CommandResult result of the command execution

run

Start a new command and return a handle to interact with it. Arguments:
  • cmd: Command to execute
  • background: False if the command should be executed in the foreground, True if the command should be executed in the background
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • on_stdout: Callback for command stdout output
  • on_stderr: Callback for command stderr output
  • stdin: If True, the command will have a stdin stream that you can send data to using sandbox.commands.send_stdin()
  • timeout: Timeout for the command connection in seconds. Using 0 will not limit the command connection time
  • request_timeout: Timeout for the request in seconds
Returns: AsyncCommandHandle handle to interact with the running command

connect

Connects to a running command. You can use AsyncCommandHandle.wait() to wait for the command to finish and get execution results. Arguments:
  • pid: Process ID of the command to connect to. You can get the list of processes using sandbox.commands.list()
  • request_timeout: Request timeout in seconds
  • timeout: Timeout for the command connection in seconds. Using 0 will not limit the command connection time
  • on_stdout: Callback for command stdout output
  • on_stderr: Callback for command stderr output
Returns: AsyncCommandHandle handle to interact with the running command

Git

Async module for running git operations in the sandbox.

__init__

Create a Git helper bound to the sandbox command runner. Arguments:
  • commands: Command runner used to execute git commands

clone

Clone a git repository into the sandbox. Arguments:
  • url: Git repository URL
  • path: Destination path for the clone
  • branch: Branch to check out
  • depth: If set, perform a shallow clone with this depth
  • username: Username for HTTP(S) authentication
  • password: Password or token for HTTP(S) authentication
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
  • dangerously_store_credentials: Store credentials in the cloned repository when True
Returns: Command result from the command runner

init

Initialize a new git repository. Arguments:
  • path: Destination path for the repository
  • bare: Create a bare repository when True
  • initial_branch: Initial branch name (for example, “main”)
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

remote_add

Add (or update) a remote for a repository. Arguments:
  • path: Repository path
  • name: Remote name (for example, “origin”)
  • url: Remote URL
  • fetch: Fetch the remote after adding it when True
  • overwrite: Overwrite the remote URL if it already exists when True
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

remote_get

Get the URL for a git remote. Returns None when the remote does not exist. Arguments:
  • path: Repository path
  • name: Remote name (for example, “origin”)
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Remote URL if present, otherwise None

status

Get repository status information. Arguments:
  • path: Repository path
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Parsed git status

branches

List branches in a repository. Arguments:
  • path: Repository path
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Parsed branch list

create_branch

Create and check out a new branch. Arguments:
  • path: Repository path
  • branch: Branch name to create
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

checkout_branch

Check out an existing branch. Arguments:
  • path: Repository path
  • branch: Branch name to check out
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

delete_branch

Delete a branch. Arguments:
  • path: Repository path
  • branch: Branch name to delete
  • force: Force deletion with -D when True
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

add

Stage files for commit. Arguments:
  • path: Repository path
  • files: Files to add; when omitted, adds the current directory
  • all: When True and files is omitted, stage all changes
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

commit

Create a commit in the repository. Arguments:
  • path: Repository path
  • message: Commit message
  • author_name: Commit author name
  • author_email: Commit author email
  • allow_empty: Allow empty commits when True
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

reset

Reset the current HEAD to a specified state. Arguments:
  • path: Repository path
  • mode: Reset mode (soft, mixed, hard, merge, keep)
  • target: Commit, branch, or ref to reset to (defaults to HEAD)
  • paths: Paths to reset
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

restore

Restore working tree files or unstage changes. Arguments:
  • path: Repository path
  • paths: Paths to restore (use [”.”] for all)
  • staged: When True, restore the index (unstage)
  • worktree: When True, restore working tree files
  • source: Restore from the given source (commit, branch, or ref)
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

push

Push commits to a remote. Arguments:
  • path: Repository path
  • remote: Remote name, e.g. origin
  • branch: Branch name to push
  • set_upstream: Set upstream tracking when True
  • username: Username for HTTP(S) authentication
  • password: Password or token for HTTP(S) authentication
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

pull

Pull changes from a remote. Arguments:
  • path: Repository path
  • remote: Remote name, e.g. origin
  • branch: Branch name to pull
  • username: Username for HTTP(S) authentication
  • password: Password or token for HTTP(S) authentication
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

set_config

Set a git config value. Use scope="local" together with path to configure a specific repository. Arguments:
  • key: Git config key (e.g. pull.rebase)
  • value: Git config value
  • scope: Config scope: global, local, or system
  • path: Repository path required when scope is local
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

get_config

Get a git config value. Returns None when the key is not set in the requested scope. Arguments:
  • key: Git config key (e.g. pull.rebase)
  • scope: Config scope: global, local, or system
  • path: Repository path required when scope is local
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Config value if present, otherwise None

dangerously_authenticate

Dangerously authenticate git globally via the credential helper. This persists credentials in the credential store and may be accessible to agents running on the sandbox. Prefer short-lived credentials when possible. Arguments:
  • username: Username for HTTP(S) authentication
  • password: Password or token for HTTP(S) authentication
  • host: Host to authenticate for, defaults to github.com
  • protocol: Protocol to authenticate for, defaults to https
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

configure_user

Configure git user name and email. Arguments:
  • name: Git user name
  • email: Git user email
  • scope: Config scope: global, local, or system
  • path: Repository path required when scope is local
  • envs: Environment variables used for the command
  • user: User to run the command as
  • cwd: Working directory to run the command
  • timeout: Timeout for the command connection in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Command result from the command runner

AsyncWatchHandle

Handle for watching a directory in the sandbox filesystem. Use .stop() to stop watching the directory.

stop

Stop watching the directory.

Filesystem

Module for interacting with the filesystem in the sandbox.

read

Read file content as a str. Arguments:
  • path: Path to the file
  • user: Run the operation as this user
  • format: Format of the file content—text by default
  • request_timeout: Timeout for the request in seconds
  • gzip: Use gzip compression for the request
Returns: File content as a str

read

Read file content as a bytearray. Arguments:
  • path: Path to the file
  • user: Run the operation as this user
  • format: Format of the file content—bytes
  • request_timeout: Timeout for the request in seconds
  • gzip: Use gzip compression for the request
Returns: File content as a bytearray

read

Read file content as a AsyncIterator[bytes]. Arguments:
  • path: Path to the file
  • user: Run the operation as this user
  • format: Format of the file content—stream
  • request_timeout: Timeout for the request in seconds
  • gzip: Use gzip compression for the request
Returns: File content as an AsyncIterator[bytes]

write

Write content to a file on the path. Writing to a file that doesn’t exist creates the file. Writing to a file that already exists overwrites the file. Writing to a file at path that doesn’t exist creates the necessary directories. Arguments:
  • path: Path to the file
  • data: Data to write to the file, can be a str, bytes, or IO.
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
  • gzip: Use gzip compression for the request
  • use_octet_stream: Upload using application/octet-stream instead of multipart/form-data. Defaults to False. Requires envd 0.5.7 or later — when not supported, the upload falls back to multipart/form-data.
Returns: Information about the written file

write_files

Writes multiple files. Writes a list of files to the filesystem. When writing to a file that doesn’t exist, the file will get created. When writing to a file that already exists, the file will get overwritten. When writing to a file at path that doesn’t exist, the necessary directories will be created. Arguments:
  • files: list of files to write as WriteEntry objects, each containing path and data
  • user: Run the operation as this user
  • request_timeout: Timeout for the request
  • gzip: Use gzip compression for the request
  • use_octet_stream: Upload using application/octet-stream instead of multipart/form-data. Defaults to False. Requires envd 0.5.7 or later — when not supported, the upload falls back to multipart/form-data.
Returns: Information about the written files

list

List entries in a directory. Arguments:
  • path: Path to the directory
  • depth: Depth of the directory to list
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
Returns: List of entries in the directory

exists

Check if a file or a directory exists. Arguments:
  • path: Path to a file or a directory
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
Returns: True if the file or directory exists, False otherwise

get_info

Get information about a file or directory. Arguments:
  • path: Path to a file or a directory
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
Returns: Information about the file or directory like name, type, and path

remove

Remove a file or a directory. Arguments:
  • path: Path to a file or a directory
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds

rename

Rename a file or directory. Arguments:
  • old_path: Path to the file or directory to rename
  • new_path: New path to the file or directory
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
Returns: Information about the renamed file or directory

make_dir

Create a new directory and all directories along the way if needed on the specified path. Arguments:
  • path: Path to a new directory. For example ‘/dirA/dirB’ when creating ‘dirB’.
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
Returns: True if the directory was created, False if the directory already exists

watch_dir

Watch directory for filesystem events. Arguments:
  • path: Path to a directory to watch
  • on_event: Callback to call on each event in the directory
  • on_exit: Callback to call when the watching ends
  • user: Run the operation as this user
  • request_timeout: Timeout for the request in seconds
  • timeout: Timeout for the watch operation in seconds. Using 0 will not limit the watch time
  • recursive: Watch directory recursively
Returns: AsyncWatchHandle object for stopping watching directory

AsyncSandboxPaginator

Paginator for listing sandboxes. Example:

next_items

Returns the next page of sandboxes. Call this method only if has_next is True, otherwise it will raise an exception. Arguments:
  • opts: Per-call connection options (e.g. api_key, domain, headers, request_timeout). When provided, this call uses these options instead of the ones the paginator was constructed with.
Returns: List of sandboxes

AsyncSnapshotPaginator

Paginator for listing snapshots. Example:

next_items

Returns the next page of snapshots. Call this method only if has_next is True, otherwise it will raise an exception. Arguments:
  • opts: Per-call connection options (e.g. api_key, domain, headers, request_timeout). When provided, this call uses these options instead of the ones the paginator was constructed with.
Returns: List of snapshots

AsyncSandbox

E2B cloud sandbox is a secure and isolated cloud environment. The sandbox allows you to:
  • Access Linux OS
  • Create, list, and delete files and directories
  • Run commands
  • Run isolated code
  • Access the internet
Check docs here. Use the AsyncSandbox.create() to create a new sandbox. Example:

files

Module for interacting with the sandbox filesystem.

commands

Module for running commands in the sandbox.

pty

Module for interacting with the sandbox pseudo-terminal.

git

Module for running git operations in the sandbox.

__init__

Use AsyncSandbox.create() to create a new sandbox instead.

is_running

Check if the sandbox is running. Arguments:
  • request_timeout: Timeout for the request in seconds
Returns: True if the sandbox is running, False otherwise Example

create

Create a new sandbox. By default, the sandbox is created from the default base sandbox template. Arguments:
  • template: Sandbox template name or ID
  • timeout: Timeout for the sandbox in seconds, default to 300 seconds. The maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users.
  • metadata: Custom metadata for the sandbox
  • envs: Custom environment variables for the sandbox
  • secure: Envd is secured with access token and cannot be used without it, defaults to True.
  • allow_internet_access: Allow sandbox to access the internet, defaults to True. If set to False, it works the same as setting network deny_out to [0.0.0.0/0].
  • mcp: MCP server to enable in the sandbox
  • network: Sandbox network configuration. allow_out/deny_out may also be a callable receiving a :class:SandboxNetworkSelectorContext (ctx.all_traffic, ctx.rules) and returning a list of strings. Per-host transform rules are nested under network.rules.
  • lifecycle: Sandbox lifecycle configuration — on_timeout: "kill" (default) or "pause"; auto_resume: False (default) or True (only when on_timeout="pause"). Example: {"on_timeout": "pause", "auto_resume": True}
  • volume_mounts: Dictionary mapping mount paths to AsyncVolume instances or volume names
Returns: A Sandbox instance for the new sandbox Use this method instead of using the constructor to create a new sandbox.

connect

Connect to a sandbox. If the sandbox is paused, it will be automatically resumed. Sandbox must be either running or be paused. With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc). Arguments:
  • timeout: Timeout for the sandbox in seconds For running sandboxes, the timeout will update only if the new timeout is longer than the existing one.
Returns: A running sandbox instance @example

connect

Connect to a sandbox. If the sandbox is paused, it will be automatically resumed. Sandbox must be either running or be paused. With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc). Arguments:
  • sandbox_id: Sandbox ID
  • timeout: Timeout for the sandbox in seconds For running sandboxes, the timeout will update only if the new timeout is longer than the existing one.
Returns: A running sandbox instance @example

connect

Connect to a sandbox. If the sandbox is paused, it will be automatically resumed. Sandbox must be either running or be paused. With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc). Arguments:
  • timeout: Timeout for the sandbox in seconds For running sandboxes, the timeout will update only if the new timeout is longer than the existing one.
Returns: A running sandbox instance @example

kill

Kill the sandbox. Returns: True if the sandbox was killed, False if the sandbox was not found

kill

Kill the sandbox specified by sandbox ID. Arguments:
  • sandbox_id: Sandbox ID
Returns: True if the sandbox was killed, False if the sandbox was not found

kill

Kill the sandbox specified by sandbox ID. Returns: True if the sandbox was killed, False if the sandbox was not found

set_timeout

Set the timeout of the sandbox. This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to .set_timeout. The maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users. Arguments:
  • timeout: Timeout for the sandbox in seconds

set_timeout

Set the timeout of the specified sandbox. This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to .set_timeout. The maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users. Arguments:
  • sandbox_id: Sandbox ID
  • timeout: Timeout for the sandbox in seconds

set_timeout

Set the timeout of the specified sandbox. This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to .set_timeout. The maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users. Arguments:
  • timeout: Timeout for the sandbox in seconds

update_network

Update the network configuration of the sandbox. Replaces the current egress configuration atomically — fields that are omitted are cleared on the server. Arguments:
  • network: New network configuration.

update_network

Update the network configuration of the sandbox specified by sandbox ID. Replaces the current egress configuration atomically — fields that are omitted are cleared on the server. Arguments:
  • sandbox_id: Sandbox ID.
  • network: New network configuration.

update_network

Update the network configuration of the sandbox. Replaces the current egress configuration atomically — fields that are omitted are cleared on the server. Arguments:
  • network: New network configuration.

get_info

Get sandbox information like sandbox ID, template, metadata, started at/end at date. Returns: Sandbox info

get_info

Get sandbox information like sandbox ID, template, metadata, started at/end at date. Arguments:
  • sandbox_id: Sandbox ID
Returns: Sandbox info

get_info

Get sandbox information like sandbox ID, template, metadata, started at/end at date. Returns: Sandbox info

get_metrics

Get the metrics of the current sandbox. Arguments:
  • start: Start time for the metrics, defaults to the start of the sandbox
  • end: End time for the metrics, defaults to the current time
Returns: List of sandbox metrics containing CPU, memory and disk usage information

get_metrics

Get the metrics of the sandbox specified by sandbox ID. Arguments:
  • sandbox_id: Sandbox ID
  • start: Start time for the metrics, defaults to the start of the sandbox
  • end: End time for the metrics, defaults to the current time
Returns: List of sandbox metrics containing CPU, memory and disk usage information

get_metrics

Get the metrics of the current sandbox. Arguments:
  • start: Start time for the metrics, defaults to the start of the sandbox
  • end: End time for the metrics, defaults to the current time
Returns: List of sandbox metrics containing CPU, memory and disk usage information

pause

Pause the sandbox. Returns: Sandbox ID that can be used to resume the sandbox

pause

Pause the sandbox specified by sandbox ID. Arguments:
  • sandbox_id: Sandbox ID
Returns: Sandbox ID that can be used to resume the sandbox

pause

Pause the sandbox. Returns: Sandbox ID that can be used to resume the sandbox

beta_pause

:deprecated: Use pause() instead.

create_snapshot

Create a snapshot of the sandbox’s current state. The sandbox will be paused while the snapshot is being created. The snapshot can be used to create new sandboxes with the same filesystem and state. Snapshots are persistent and survive sandbox deletion. Use the returned snapshot_id with AsyncSandbox.create(snapshot_id) to create a new sandbox from the snapshot. Arguments:
  • name: Optional name for the snapshot template. If a snapshot template with this name already exists, a new build will be assigned to the existing template instead of creating a new one.
Returns: Snapshot information including the snapshot ID and names

create_snapshot

Create a snapshot from the sandbox specified by sandbox ID. The sandbox will be paused while the snapshot is being created. Arguments:
  • sandbox_id: Sandbox ID
  • name: Optional name for the snapshot template. If a snapshot template with this name already exists, a new build will be assigned to the existing template instead of creating a new one.
Returns: Snapshot information including the snapshot ID and names

create_snapshot

Create a snapshot of the sandbox’s current state. The sandbox will be paused while the snapshot is being created. The snapshot can be used to create new sandboxes with the same filesystem and state. Snapshots are persistent and survive sandbox deletion. Use the returned snapshot_id with AsyncSandbox.create(snapshot_id) to create a new sandbox from the snapshot. Arguments:
  • name: Optional name for the snapshot template. If a snapshot template with this name already exists, a new build will be assigned to the existing template instead of creating a new one.
Returns: Snapshot information including the snapshot ID and names

list_snapshots

List snapshots for this sandbox. Arguments:
  • limit: Maximum number of snapshots to return per page
  • next_token: Token for pagination
Returns: Paginator for listing snapshots

list_snapshots

List all snapshots. Arguments:
  • sandbox_id: Filter snapshots by source sandbox ID
  • limit: Maximum number of snapshots to return per page
  • next_token: Token for pagination
Returns: Paginator for listing snapshots

list_snapshots

List snapshots for this sandbox. Arguments:
  • limit: Maximum number of snapshots to return per page
  • next_token: Token for pagination
Returns: Paginator for listing snapshots

delete_snapshot

Delete a snapshot. Arguments:
  • snapshot_id: Snapshot ID
Returns: True if the snapshot was deleted, False if it was not found

get_mcp_token

Get the MCP token for the sandbox. Returns: MCP token for the sandbox, or None if MCP is not enabled.

SandboxApi

list

List all running sandboxes. Arguments:
  • query: Filter the list of sandboxes by metadata or state, e.g. SandboxListQuery(metadata={"key": "value"}) or SandboxListQuery(state=[SandboxState.RUNNING])
  • limit: Maximum number of sandboxes to return per page
  • next_token: Token for pagination
Returns: List of running sandboxes