SandboxApi
Python
list
Python
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
Python
list
Python
request_timeout
: Timeout for the request in seconds
kill
Python
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
Python
sandbox.commands.list()
.
:param data: Data to send to the command
:param request_timeout: Timeout for the request in seconds
run
Python
cmd
: Command to executebackground
:False
if the command should be executed in the foreground,True
if 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 outputtimeout
: Timeout for the command connection in seconds. Using0
will not limit the command connection timerequest_timeout
: Timeout for the request in seconds
CommandResult
result of the command execution
run
Python
cmd
: Command to executebackground
:False
if the command should be executed in the foreground,True
if 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 outputtimeout
: Timeout for the command connection in seconds. Using0
will not limit the command connection timerequest_timeout
: Timeout for the request in seconds
AsyncCommandHandle
handle to interact with the running command
connect
Python
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 usingsandbox.commands.list()
request_timeout
: Request timeout in secondstimeout
: Timeout for the command connection in seconds. Using0
will not limit the command connection timeon_stdout
: Callback for command stdout outputon_stderr
: Callback for command stderr output
AsyncCommandHandle
handle to interact with the running command
AsyncCommandHandle
Python
pid
Python
stdout
Python
stderr
Python
error
Python
exit_code
Python
0
if the command finished successfully.
It is None
if the command is still running.
disconnect
Python
sandbox.commands.connect
method.
wait
Python
CommandExitException
.
Returns:
CommandResult
result of command execution
kill
Python
SIGKILL
signal to kill the command
Returns:
True
if the command was killed successfully, False
if the command was not found
Pty
Python
kill
Python
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
Python
pid
: Process ID of the PTYdata
: Input data to sendrequest_timeout
: Timeout for the request in seconds
create
Python
size
: Size of the PTYon_data
: Callback to handle PTY datauser
: 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
Python
pid
: Process ID of the PTYsize
: New size of the PTYrequest_timeout
: Timeout for the request in seconds
AsyncWatchHandle
Python
.stop()
to stop watching the directory.
stop
Python
Filesystem
Python
read
Python
str
.
Arguments:
path
: Path to the fileuser
: Run the operation as this userformat
: Format of the file content—text
by defaultrequest_timeout
: Timeout for the request in seconds
str
read
Python
bytearray
.
Arguments:
path
: Path to the fileuser
: Run the operation as this userformat
: Format of the file content—bytes
request_timeout
: Timeout for the request in seconds
bytearray
read
Python
AsyncIterator[bytes]
.
Arguments:
path
: Path to the fileuser
: Run the operation as this userformat
: Format of the file content—stream
request_timeout
: Timeout for the request in seconds
AsyncIterator[bytes]
write
Python
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
Python
files
: list of files to write asWriteEntry
objects, each containingpath
anddata
user
: Run the operation as this userrequest_timeout
: Timeout for the request
list
Python
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
Python
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
Python
path
: Path to a file or a directoryuser
: Run the operation as this userrequest_timeout
: Timeout for the request in seconds
remove
Python
path
: Path to a file or a directoryuser
: Run the operation as this userrequest_timeout
: Timeout for the request in seconds
rename
Python
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
Python
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
Python
path
: Path to a directory to watchon_event
: Callback to call on each event in the directoryon_exit
: Callback to call when the watching endsuser
: Run the operation as this userrequest_timeout
: Timeout for the request in secondstimeout
: Timeout for the watch operation in seconds. Using0
will not limit the watch timerecursive
: Watch directory recursively
AsyncWatchHandle
object for stopping watching directory
AsyncSandboxPaginator
Python
Python
next_items
Python
has_next
is True
, otherwise it will raise an exception.
Returns:
List of sandboxes
AsyncSandbox
Python
- Access Linux OS
- Create, list, and delete files and directories
- Run commands
- Run isolated code
- Access the internet
AsyncSandbox.create()
to create a new sandbox.
Example:
Python
files
Python
commands
Python
pty
Python
__init__
Python
AsyncSandbox.create()
to create a new sandbox instead.
is_running
Python
request_timeout
: Timeout for the request in seconds
True
if the sandbox is running, False
otherwise
Example
Python
create
Python
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
Python
timeout
: Timeout for the sandbox in seconds
Python
connect
Python
sandbox_id
: Sandbox IDtimeout
: Timeout for the sandbox in seconds
Python
connect
Python
timeout
: Timeout for the sandbox in seconds
Python
kill
Python
True
if the sandbox was killed, False
if the sandbox was not found
kill
Python
sandbox_id
: Sandbox ID
True
if the sandbox was killed, False
if the sandbox was not found
kill
Python
True
if the sandbox was killed, False
if the sandbox was not found
set_timeout
Python
.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
Python
.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
Python
.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
Python
get_info
Python
sandbox_id
: Sandbox ID
get_info
Python
get_metrics
Python
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
Python
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
Python
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
Python
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
.
beta_pause
Python
beta_pause
Python
sandbox_id
: Sandbox ID
beta_pause
Python