SandboxApi
list
query: Filter the list of sandboxes by metadata or state, e.g.SandboxListQuery(metadata={"key": "value"})orSandboxListQuery(state=[SandboxState.RUNNING])limit: Maximum number of sandboxes to return per pagenext_token: Token for pagination
Commands
list
request_timeout: Timeout for the request in seconds
kill
SIGKILL signal to kill the command.
Arguments:
pid: Process ID of the command. You can get the list of processes usingsandbox.commands.list()request_timeout: Timeout for the request in seconds
True if the command was killed, False if the command was not found
send_stdin
sandbox.commands.list().
:param data: Data to send to the command
:param request_timeout: Timeout for the request in seconds
run
cmd: Command to executebackground:Falseif the command should be executed in the foreground,Trueif the command should be executed in the backgroundenvs: Environment variables used for the commanduser: User to run the command ascwd: Working directory to run the commandon_stdout: Callback for command stdout outputon_stderr: Callback for command stderr outputstdin: IfTrue, the command will have a stdin stream that you can send data to usingsandbox.commands.send_stdin()timeout: Timeout for the command connection in seconds. Using0will not limit the command connection timerequest_timeout: Timeout for the request in seconds
CommandResult result of the command execution
run
cmd: Command to executebackground:Falseif the command should be executed in the foreground,Trueif the command should be executed in the backgroundenvs: Environment variables used for the commanduser: User to run the command ascwd: Working directory to run the commandstdin: IfTrue, the command will have a stdin stream that you can send data to usingsandbox.commands.send_stdin()timeout: Timeout for the command connection in seconds. Using0will not limit the command connection timerequest_timeout: Timeout for the request in seconds
CommandHandle handle to interact with the running command
connect
CommandHandle.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 usingsandbox.commands.list()timeout: Timeout for the connection in seconds. Using0will not limit the connection timerequest_timeout: Timeout for the request in seconds
CommandHandle handle to interact with the running command
CommandHandle
pid
__iter__
disconnect
sandbox.commands.connect method.
wait
CommandExitException.
Arguments:
on_pty: Callback for pty outputon_stdout: Callback for stdout outputon_stderr: Callback for stderr output
CommandResult result of command execution
kill
SIGKILL signal to kill the command.
Returns:
Whether the command was killed successfully
Pty
kill
pid: Process ID of the PTYrequest_timeout: Timeout for the request in seconds
true if the PTY was killed, false if the PTY was not found
send_stdin
pid: Process ID of the PTYdata: Input data to sendrequest_timeout: Timeout for the request in seconds
create
size: Size of the PTYuser: User to use for the PTYcwd: Working directory for the PTYenvs: Environment variables for the PTYtimeout: Timeout for the PTY in secondsrequest_timeout: Timeout for the request in seconds
resize
pid: Process ID of the PTYsize: New size of the PTYrequest_timeout: Timeout for the request in secondss
WatchHandle
.stop() to stop watching the directory.
stop
get_new_events
Filesystem
read
str.
Arguments:
path: Path to the fileuser: Run the operation as this userformat: Format of the file content—textby defaultrequest_timeout: Timeout for the request in seconds
str
read
bytearray.
Arguments:
path: Path to the fileuser: Run the operation as this userformat: Format of the file content—bytesrequest_timeout: Timeout for the request in seconds
bytearray
read
Iterator[bytes].
Arguments:
path: Path to the fileuser: Run the operation as this userformat: Format of the file content—streamrequest_timeout: Timeout for the request in seconds
Iterator[bytes]
write
path: Path to the filedata: Data to write to the file, can be astr,bytes, orIO.user: Run the operation as this userrequest_timeout: Timeout for the request in seconds
write_files
files: list of files to write asWriteEntryobjects, each containingpathanddatauser: Run the operation as this userrequest_timeout: Timeout for the request
list
path: Path to the directorydepth: Depth of the directory to listuser: Run the operation as this userrequest_timeout: Timeout for the request in seconds
exists
path: Path to a file or a directoryuser: Run the operation as this userrequest_timeout: Timeout for the request in seconds
True if the file or directory exists, False otherwise
get_info
path: Path to a file or a directoryuser: Run the operation as this userrequest_timeout: Timeout for the request in seconds
remove
path: Path to a file or a directoryuser: Run the operation as this userrequest_timeout: Timeout for the request in seconds
rename
old_path: Path to the file or directory to renamenew_path: New path to the file or directoryuser: Run the operation as this userrequest_timeout: Timeout for the request in seconds
make_dir
path: Path to a new directory. For example ‘/dirA/dirB’ when creating ‘dirB’.user: Run the operation as this userrequest_timeout: Timeout for the request in seconds
True if the directory was created, False if the directory already exists
watch_dir
path: Path to a directory to watchuser: Run the operation as this userrequest_timeout: Timeout for the request in secondsrecursive: Watch directory recursively
WatchHandle object for stopping watching directory
SandboxPaginator
next_items
has_next is True, otherwise it will raise an exception.
Returns:
List of sandboxes
Sandbox
- Access Linux OS
- Create, list, and delete files and directories
- Run commands
- Run isolated code
- Access the internet
Sandbox.create() to create a new sandbox.
Example:
files
commands
pty
__init__
Sandbox.create() to create a new sandbox instead.
is_running
request_timeout: Timeout for the request in seconds
True if the sandbox is running, False otherwise
Example
create
base sandbox template.
Arguments:
template: Sandbox template name or IDtimeout: 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 sandboxenvs: Custom environment variables for the sandboxsecure: Envd is secured with access token and cannot be used without it, defaults toTrue.allow_internet_access: Allow sandbox to access the internet, defaults toTrue.
connect
timeout: Timeout for the sandbox in seconds
sandbox_id: Sandbox IDtimeout: Timeout for the sandbox in seconds
connect
timeout: Timeout for the sandbox in seconds
kill
True if the sandbox was killed, False if the sandbox was not found
kill
sandbox_id: Sandbox ID
True if the sandbox was killed, False if the sandbox was not found
kill
True if the sandbox was killed, False if the sandbox was not found
set_timeout
.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_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 IDtimeout: Timeout for the sandbox in seconds
set_timeout
.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
get_info
get_info
sandbox_id: Sandbox ID
get_info
get_metrics
start: Start time for the metrics, defaults to the start of the sandboxend: End time for the metrics, defaults to the current time
get_metrics
sandbox_id: Sandbox IDstart: Start time for the metrics, defaults to the start of the sandboxend: End time for the metrics, defaults to the current time
get_metrics
start: Start time for the metrics, defaults to the start of the sandboxend: End time for the metrics, defaults to the current time
beta_create
base sandbox template.
Arguments:
template: Sandbox template name or IDtimeout: 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.auto_pause: Automatically pause the sandbox after the timeout expires. Defaults toFalse.metadata: Custom metadata for the sandboxenvs: Custom environment variables for the sandboxsecure: Envd is secured with access token and cannot be used without it, defaults toTrue.allow_internet_access: Allow sandbox to access the internet, defaults toTrue.mcp: MCP server to enable in the sandbox
beta_pause
beta_pause
sandbox_id: Sandbox ID