SandboxApi
list
api_key: API key to use for authentication, defaults toE2B_API_KEYenvironment variablequery: Filter the list of sandboxes, e.g. by metadataSandboxQuery(metadata={"key": "value"}), if there are multiple filters they are combined with AND.domain: Domain to use for the request, only relevant for self-hosted environmentsdebug: Enable debug mode, all requested are then sent to localhostrequest_timeout: Timeout for the request in secondsheaders: Additional headers to send with the requestproxy: Proxy to use for the request
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
AsyncIterator[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
AsyncIterator[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: list of files to writeuser: Run the operation as this userrequest_timeout: Timeout for the request
write
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
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 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. Using0will not limit the watch timerecursive: Watch directory recursively
AsyncWatchHandle object for stopping watching directory
AsyncWatchHandle
.stop() to stop watching the directory.
stop
AsyncSandbox
- 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:
files
commands
pty
sandbox_id
sandbox_domain
__init__
AsyncSandbox.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. 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 sandboxapi_key: E2B API Key to use for authentication, defaults toE2B_API_KEYenvironment variablerequest_timeout: Timeout for the request in secondsproxy: Proxy to use for the request and for the requests made to the returned sandboxsecure: Envd is secured with access token and cannot be used without it
connect
sandbox_id: Sandbox IDapi_key: E2B API Key to use for authentication, defaults toE2B_API_KEYenvironment variableproxy: Proxy to use for the request and for the requests made to the returned sandbox
request_timeout: Timeout for the request in seconds
True if the sandbox was killed, False if the sandbox was not found
kill
sandbox_id: Sandbox IDapi_key: E2B API Key to use for authentication, defaults toE2B_API_KEYenvironment variablerequest_timeout: Timeout for the request in secondsproxy: Proxy to use for the request
True if the sandbox was killed, False if the sandbox was not found
set_timeout
.set_timeout.
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 secondsrequest_timeout: Timeout for the request in seconds
set_timeout
.set_timeout.
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 secondsrequest_timeout: Timeout for the request in secondsproxy: Proxy to use for the request
get_info
request_timeout: Timeout for the request in seconds
get_info
sandbox_id: Sandbox IDapi_key: E2B API Key to use for authentication, defaults toE2B_API_KEYenvironment variabledomain: E2B domain to use for authentication, defaults toE2B_DOMAINenvironment variabledebug: Whether to use debug mode, defaults toE2B_DEBUGenvironment variablerequest_timeout: Timeout for the request in secondsheaders: Custom headers to use for the requestproxy: Proxy to use for the request
get_info
request_timeout: Timeout for the request in seconds
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 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
pid: Process ID of the PTYsize: New size of the PTYrequest_timeout: Timeout for the request in seconds
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 outputtimeout: 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 commandon_stdout: Callback for command stdout outputon_stderr: Callback for command stderr outputtimeout: Timeout for the command connection in seconds. Using0will not limit the command connection timerequest_timeout: Timeout for the request in seconds
AsyncCommandHandle handle to interact with the running command
connect
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. Using0will 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
pid
stdout
stderr
error
exit_code
0 if the command finished successfully.
It is None if the command is still running.
disconnect
sandbox.commands.connect method.
wait
CommandExitException.
Returns:
CommandResult result of command execution
kill
SIGKILL signal to kill the command
Returns:
True if the command was killed successfully, False if the command was not found