Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Update sync Python docstrings

Tomas Valentac688b267b494
diff --git a/packages/python-sdk/e2b/sandbox_async/commands/command.py b/packages/python-sdk/e2b/sandbox_async/commands/command.py
index f4ecc4c4b..4fb24ba70 100644
--- a/packages/python-sdk/e2b/sandbox_async/commands/command.py
+++ b/packages/python-sdk/e2b/sandbox_async/commands/command.py
@@ -111,7 +111,7 @@ class Commands:
: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: Request timeout
+ :param request_timeout: Timeout for the request in **seconds**
"""
try:
await self._rpc.asend_input(
@@ -184,7 +184,7 @@ class Commands:
:param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time
:param request_timeout: Timeout for the request in **seconds**
- :return: `CommandHandle` handle to interact with the running command
+ :return: `AsyncCommandHandle` handle to interact with the running command
"""
...
@@ -271,7 +271,7 @@ class Commands:
) -> AsyncCommandHandle:
"""
Connects to a running command.
- You can use `CommandHandle.wait()` to wait for the command to finish and get execution results.
+ You can use `AsyncCommandHandle.wait()` to wait for the command to finish and get execution results.
:param pid: Process ID of the command to connect to. You can get the list of processes using `sandbox.commands.list()`
:param request_timeout: Request timeout in **seconds**
@@ -279,7 +279,7 @@ class Commands:
:param on_stdout: Callback for command stdout output
:param on_stderr: Callback for command stderr output
- :return: `CommandHandle` handle to interact with the running command
+ :return: `AsyncCommandHandle` handle to interact with the running command
"""
events = self._rpc.aconnect(
process_pb2.ConnectRequest(
diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index 1f16104c6..216147c78 100644
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@ -83,6 +83,7 @@ class Filesystem:
:return: File content as a `bytearray`
"""
+ ...
@overload
async def read(
diff --git a/packages/python-sdk/e2b/sandbox_async/main.py b/packages/python-sdk/e2b/sandbox_async/main.py
index cb31e3cb1..e6fcf4153 100644
--- a/packages/python-sdk/e2b/sandbox_async/main.py
+++ b/packages/python-sdk/e2b/sandbox_async/main.py
@@ -59,7 +59,7 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
@property
def files(self) -> Filesystem:
"""
- Module for interacting with the sandbox filesystem..
+ Module for interacting with the sandbox filesystem.
"""
return self._filesystem
diff --git a/packages/python-sdk/e2b/sandbox_sync/commands/command.py b/packages/python-sdk/e2b/sandbox_sync/commands/command.py
index d933cb499..5839efd75 100644
--- a/packages/python-sdk/e2b/sandbox_sync/commands/command.py
+++ b/packages/python-sdk/e2b/sandbox_sync/commands/command.py
@@ -17,6 +17,10 @@ from e2b.sandbox_sync.commands.command_handle import CommandHandle
class Commands:
+ """
+ Module for executing commands in the sandbox.
+ """
+
def __init__(
self,
envd_api_url: str,
@@ -37,10 +41,11 @@ class Commands:
request_timeout: Optional[float] = None,
) -> List[ProcessInfo]:
"""
- Lists all running processes.
+ Lists all running commands and PTY sessions.
+
+ :param request_timeout: Timeout for the request in **seconds**
- :param request_timeout: Request timeout
- :return: List of running processes
+ :return: List of running commands and PTY sessions
"""
try:
res = self._rpc.list(
@@ -69,11 +74,13 @@ class Commands:
request_timeout: Optional[float] = None,
) -> bool:
"""
- Kills a process.
+ Kills a running command specified by its process ID.
+ It uses `SIGKILL` signal to kill the command.
- :param pid: Process ID to connect to. You can get the list of processes using `sandbox.commands.list()`.
- :param request_timeout: Request timeout
- :return: `True` if the process was killed, `False` if the process was not found
+ :param pid: Process ID of the command. You can get the list of processes using `sandbox.commands.list()`
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `True` if the command was killed, `False` if the command was not found
"""
try:
self._rpc.send_signal(
@@ -99,11 +106,11 @@ class Commands:
request_timeout: Optional[float] = None,
):
"""
- Sends data to the stdin of a process.
+ Send data to command stdin.
- :param pid Process ID to send data to. You can get the list of processes using `sandbox.commands.list()`.
- :param data: Data to send to the process
- :param request_timeout: Request timeout
+ :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**
"""
try:
self._rpc.send_input(
@@ -132,7 +139,23 @@ class Commands:
on_stderr: Optional[Callable[[str], None]] = None,
timeout: Optional[float] = 60,
request_timeout: Optional[float] = None,
- ) -> CommandResult: ...
+ ) -> CommandResult:
+ """
+ Start a new command and wait until it finishes executing.
+
+ :param cmd: Command to execute
+ :param background: **`False` if the command should be executed in the foreground**, `True` if the command should be executed in the background
+ :param envs: Environment variables used for the command
+ :param user: User to run the command as
+ :param cwd: Working directory to run the command
+ :param on_stdout: Callback for command stdout output
+ :param on_stderr: Callback for command stderr output
+ :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `CommandResult` result of the command execution
+ """
+ ...
@overload
def run(
@@ -146,7 +169,21 @@ class Commands:
on_stderr: None = None,
timeout: Optional[float] = 60,
request_timeout: Optional[float] = None,
- ) -> CommandHandle: ...
+ ) -> CommandHandle:
+ """
+ Start a new command and return a handle to interact with it.
+
+ :param cmd: Command to execute
+ :param background: `False` if the command should be executed in the foreground, **`True` if the command should be executed in the background**
+ :param envs: Environment variables used for the command
+ :param user: User to run the command as
+ :param cwd: Working directory to run the command
+ :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `CommandHandle` handle to interact with the running command
+ """
+ ...
def run(
self,
@@ -160,21 +197,6 @@ class Commands:
timeout: Optional[float] = 60,
request_timeout: Optional[float] = None,
):
- """
- Starts a new process and depending on the `background` parameter, waits for the process to finish or not.
- :param cmd Command to execute
- :param background:
- If `True`, the function will return a `ProcessHandle` object that can be used to interact with the process.
- If `False`, the function will wait for the process to finish and return a `ProcessResult` object.
- :param envs: Environment variables
- :param user: User to run the process as
- :param cwd: Working directory
- :param on_stdout: Callback for stdout
- :param on_stderr: Callback for stderr
- :param timeout: Timeout for the maximum time the process is allowed to run
- :param request_timeout: Timeout for the request
- :return: `ProcessHandle` if `background` is `True`, `ProcessResult` if `background` is `False`
- """
proc = self._start(
cmd,
envs,
@@ -244,11 +266,14 @@ class Commands:
request_timeout: Optional[float] = None,
):
"""
- Connects to an existing process.
+ Connects to a running command.
+ You can use `CommandHandle.wait()` to wait for the command to finish and get execution results.
+
+ :param pid: Process ID of the command to connect to. You can get the list of processes using `sandbox.commands.list()`
+ :param timeout: Timeout for the connection in **seconds**. Using `0` will not limit the connection time
+ :param request_timeout: Timeout for the request in **seconds**
- :param pid: Process ID to connect to. You can get the list of processes using `sandbox.commands.list()`.
- :param timeout: Timeout for the connection
- :param request_timeout: Request timeout
+ :return: `CommandHandle` handle to interact with the running command
"""
events = self._rpc.connect(
process_pb2.ConnectRequest(
diff --git a/packages/python-sdk/e2b/sandbox_sync/commands/command_handle.py b/packages/python-sdk/e2b/sandbox_sync/commands/command_handle.py
index 16d6021a1..5dbf6e0d4 100644
--- a/packages/python-sdk/e2b/sandbox_sync/commands/command_handle.py
+++ b/packages/python-sdk/e2b/sandbox_sync/commands/command_handle.py
@@ -13,14 +13,15 @@ from e2b.sandbox.commands.command_handle import (
class CommandHandle:
"""
- Class representing a process. It provides methods for waiting and killing the process.
- It is also used to iterate over the process output.
+ Command execution handle.
+
+ It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
"""
@property
def pid(self):
"""
- Get the process ID.
+ Command process ID.
"""
return self._pid
@@ -43,6 +44,11 @@ class CommandHandle:
self._iteration_exception: Optional[Exception] = None
def __iter__(self):
+ """
+ Iterate over the command output.
+
+ :return: Generator of command outputs
+ """
return self._handle_events()
def _handle_events(
@@ -78,7 +84,10 @@ class CommandHandle:
def disconnect(self) -> None:
"""
- Disconnect from the process. It does not kill the process. It only stops receiving events from the process.
+ Disconnect 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.
"""
self._events.close()
@@ -89,13 +98,14 @@ class CommandHandle:
on_stderr: Optional[Callable[[str], None]] = None,
) -> CommandResult:
"""
- Waits for the process to finish and returns the result.
- If the process exits with a non-zero exit code, it throws a `CommandExitException`.
+ Wait for the command to finish and returns the result.
+ If the command exits with a non-zero exit code, it throws a `CommandExitException`.
:param on_pty: Callback for pty output
:param on_stdout: Callback for stdout output
:param on_stderr: Callback for stderr output
- :return: Process result
+
+ :return: `CommandResult` result of command execution
"""
try:
for stdout, stderr, pty in self:
@@ -128,7 +138,10 @@ class CommandHandle:
def kill(self) -> bool:
"""
- Kills the process.
- :return: Whether the process was killed successfully
+ Kills the command.
+
+ It uses `SIGKILL` signal to kill the command.
+
+ :return: Whether the command was killed successfully
"""
return self._handle_kill()
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index 1aa176c30..094d82a71 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -19,7 +19,7 @@ from e2b.sandbox_sync.filesystem.watch_handle import WatchHandle
class Filesystem:
"""
- Manager for interacting with the filesystem in the sandbox.
+ Module for interacting with the filesystem in the sandbox.
"""
def __init__(
@@ -49,7 +49,18 @@ class Filesystem:
format: Literal["text"] = "text",
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> str: ...
+ ) -> str:
+ """
+ Read file content as a `str`.
+
+ :param path: Path to the file
+ :param user: Run the operation as this user
+ :param format: Format of the file content—`text` by default
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: File content as a `str`
+ """
+ ...
@overload
def read(
@@ -58,7 +69,18 @@ class Filesystem:
format: Literal["bytes"],
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> bytearray: ...
+ ) -> bytearray:
+ """
+ Read file content as a `bytearray`.
+
+ :param path: Path to the file
+ :param user: Run the operation as this user
+ :param format: Format of the file content—`bytes`
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: File content as a `bytearray`
+ """
+ ...
@overload
def read(
@@ -67,7 +89,18 @@ class Filesystem:
format: Literal["stream"],
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> Iterator[bytes]: ...
+ ) -> Iterator[bytes]:
+ """
+ Read file content as a `Iterator[bytes]`.
+
+ :param path: Path to the file
+ :param user: Run the operation as this user
+ :param format: Format of the file content—`stream`
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: File content as an `Iterator[bytes]`
+ """
+ ...
def read(
self,
@@ -76,15 +109,6 @@ class Filesystem:
user: Username = "user",
request_timeout: Optional[float] = None,
):
- """
- Reads a whole file content and returns it in requested format (text by default).
-
- :param path: Path to the file
- :param format: Format of the file content
- :param user: Run the operation as this user
- :param request_timeout: Timeout for the request
- :return File content in requested format
- """
r = self._envd_api.get(
ENVD_API_FILES_ROUTE,
params={"path": path, "username": user},
@@ -110,15 +134,19 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> EntryInfo:
"""
- Writes content to a file on the path.
- 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 that's in a directory that doesn't exist, the directory will get created.
+ 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.
:param path: Path to the file
- :param data: Data to write to the file
+ :param data: Data to write to the file, can be a `str`, `bytes`, or `IO`.
:param user: Run the operation as this user
- :param request_timeout: Timeout for the request
+ :param request_timeout: Timeout for the request in **seconds**
+
:return: Information about the written file
"""
if isinstance(data, TextIOBase):
@@ -150,11 +178,12 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> List[EntryInfo]:
"""
- Lists entries in a directory.
+ List entries in a directory.
:param path: Path to the directory
:param user: Run the operation as this user
- :param request_timeout: Timeout for the request
+ :param request_timeout: Timeout for the request in **seconds**
+
:return: List of entries in the directory
"""
try:
@@ -186,11 +215,13 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> bool:
"""
- Checks if a file or a directory exists.
+ Check if a file or a directory exists.
:param path: Path to a file or a directory
- :param user Run the operation as this user
- :param request_timeout Timeout for the request
+ :param user: Run the operation as this user
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `True` if the file or directory exists, `False` otherwise
"""
try:
self._rpc.stat(
@@ -215,10 +246,11 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> None:
"""
- Removes a file or a directory.
+ Remove a file or a directory.
+
:param path: Path to a file or a directory
:param user: Run the operation as this user
- :param request_timeout: Timeout for the request
+ :param request_timeout: Timeout for the request in **seconds**
"""
try:
self._rpc.remove(
@@ -239,12 +271,12 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> EntryInfo:
"""
- Renames a file or directory from one path to another.
+ Rename a file or directory.
- :param old_path Path to the file or directory to move
- :param new_path Path to move the file or directory to
- :param user Run the operation as this user
- :param request_timeout Timeout for the request
+ :param old_path: Path to the file or directory to rename
+ :param new_path: New path to the file or directory
+ :param user: Run the operation as this user
+ :param request_timeout: Timeout for the request in **seconds**
:return: Information about the renamed file or directory
"""
@@ -275,12 +307,13 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> bool:
"""
- Creates a new directory and all directories along the way if needed on the specified path.
+ Create a new directory and all directories along the way if needed on the specified path.
:param path: Path to a new directory. For example '/dirA/dirB' when creating 'dirB'.
:param user: Run the operation as this user
- :param request_timeout: Timeout for the request
- :return: True if the directory was created, False if the directory already exists
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `True` if the directory was created, `False` if the directory already exists
"""
try:
self._rpc.make_dir(
@@ -305,13 +338,13 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> WatchHandle:
"""
- Watches directory for filesystem events.
- To get events, use the `get_new_events` method on the returned handle.
+ Watch directory for filesystem events.
- :param path: Path to a directory that will be watched
+ :param path: Path to a directory to watch
:param user: Run the operation as this user
- :param request_timeout: Timeout for the request
- :return: Watcher handle
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `WatchHandle` object for stopping watching directory
"""
try:
r = self._rpc.create_watcher(
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py
index 8f4fae891..bbf531c57 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py
@@ -12,7 +12,10 @@ from e2b.sandbox.filesystem.watch_handle import FilesystemEvent, map_event_type
class WatchHandle:
"""
- Handle for watching filesystem events. It is used to iterate over the events in the watched directory.
+ Handle for watching filesystem events.
+ It is used to get the latest events that have occurred in the watched directory.
+
+ Use `.stop()` to stop watching the directory.
"""
def __init__(
@@ -26,7 +29,8 @@ class WatchHandle:
def stop(self):
"""
- Stop watching the directory. After you stop the watcher you won't be able to get the events anymore.
+ Stop watching the directory.
+ After you stop the watcher you won't be able to get the events anymore.
"""
try:
self._rpc.remove_watcher(RemoveWatcherRequest(watcher_id=self._watcher_id))
@@ -37,7 +41,9 @@ class WatchHandle:
def get_new_events(self) -> List[FilesystemEvent]:
"""
- Get the latest events that have occurred in the watched directory since the last call, or from the beginning of the watching, up to now.
+ Get the latest events that have occurred in the watched directory since the last call, or from the beginning of the watching, up until now.
+
+ :return: List of filesystem events
"""
if self._closed:
raise SandboxException("The watcher is already stopped")
diff --git a/packages/python-sdk/e2b/sandbox_sync/main.py b/packages/python-sdk/e2b/sandbox_sync/main.py
index a0132ae25..e6abe0b46 100644
--- a/packages/python-sdk/e2b/sandbox_sync/main.py
+++ b/packages/python-sdk/e2b/sandbox_sync/main.py
@@ -29,18 +29,16 @@ class TransportWithLogger(httpx.HTTPTransport):
class Sandbox(SandboxSetup, SandboxApi):
"""
- E2B cloud sandbox gives your agent a full cloud development environment that's sandboxed.
+ E2B cloud sandbox is a secure and isolated cloud environment.
- That means:
- - Access to Linux OS
- - Using filesystem (create, list, and delete files and directories)
+ The sandbox allows you to:
+ - Access Linux OS
+ - Create, list, and delete files and directories
- Run commands
- - Sandboxed - you can run any code
- - Access to the internet
+ - Run isolated code
+ - Access the internet
- Check usage docs - https://e2b.dev/docs/sandbox/overview
-
- These cloud sandboxes are meant to be used for agents. Like a sandboxed playgrounds, where the agent can do whatever it wants.
+ Check docs [here](https://e2b.dev/docs).
Use the `Sandbox()` to create a new sandbox.
@@ -53,21 +51,21 @@ class Sandbox(SandboxSetup, SandboxApi):
@property
def files(self) -> Filesystem:
"""
- Filesystem module for interacting with the sandbox's filesystem
+ Module for interacting with the sandbox filesystem.
"""
return self._filesystem
@property
def commands(self) -> Commands:
"""
- Commands module for interacting with the sandbox's processes
+ Module for running commands in the sandbox.
"""
return self._commands
@property
def pty(self) -> Pty:
"""
- PTY module for interacting with the sandbox's pseudo-terminal
+ Module for interacting with the sandbox pseudo-terminal.
"""
return self._pty
@@ -80,16 +78,10 @@ class Sandbox(SandboxSetup, SandboxApi):
@property
def envd_api_url(self) -> str:
- """
- Get the sandbox API URL
- """
return self._envd_api_url
@property
def connection_config(self) -> ConnectionConfig:
- """
- Get the ConnectionConfig object
- """
return self._connection_config
def __init__(
@@ -104,7 +96,20 @@ class Sandbox(SandboxSetup, SandboxApi):
sandbox_id: Optional[str] = None,
request_timeout: Optional[float] = None,
):
- """Instantiate sandbox"""
+ """
+ Create a new sandbox.
+
+ By default, the sandbox is created from the default `base` sandbox template.
+
+ :param template: Sandbox template name or ID
+ :param timeout: 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
+ :param metadata: Custom metadata for the sandbox
+ :param envs: Custom environment variables for the sandbox
+ :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: sandbox instance for the new sandbox
+ """
super().__init__()
if sandbox_id and (metadata is not None or template is not None):
@@ -167,6 +172,8 @@ class Sandbox(SandboxSetup, SandboxApi):
"""
Check if the sandbox is running.
+ :param request_timeout: Timeout for the request in **seconds**
+
:return: `True` if the sandbox is running, `False` otherwise
Example
@@ -207,11 +214,12 @@ class Sandbox(SandboxSetup, SandboxApi):
):
"""
Connects to an existing Sandbox.
+ With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
+
:param sandbox_id: Sandbox ID
- :param api_key: E2B API Key
- :param domain: E2B Domain (use only if you self-host E2B)
- :param debug: For developing purposes, uses a local sandbox
- :return: Sandbox object
+ :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+
+ :return: sandbox instance for the existing sandbox
@example
```python
@@ -235,7 +243,15 @@ class Sandbox(SandboxSetup, SandboxApi):
self.kill()
@overload
- def kill(self, request_timeout: Optional[float] = None) -> bool: ...
+ def kill(self, request_timeout: Optional[float] = None) -> bool:
+ """
+ Kill the sandbox.
+
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `True` if the sandbox was killed, `False` if the sandbox was not found
+ """
+ ...
@overload
@staticmethod
@@ -245,7 +261,17 @@ class Sandbox(SandboxSetup, SandboxApi):
domain: Optional[str] = None,
debug: Optional[bool] = None,
request_timeout: Optional[float] = None,
- ) -> bool: ...
+ ) -> bool:
+ """
+ Kill the sandbox specified by sandbox ID.
+
+ :param sandbox_id: Sandbox ID
+ :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+ :param request_timeout: Timeout for the request in **seconds**
+
+ :return: `True` if the sandbox was killed, `False` if the sandbox was not found
+ """
+ ...
@class_method_variant("_cls_kill")
def kill(self, request_timeout: Optional[float] = None) -> bool: # type: ignore
@@ -272,7 +298,18 @@ class Sandbox(SandboxSetup, SandboxApi):
self,
timeout: int,
request_timeout: Optional[float] = None,
- ) -> None: ...
+ ) -> None:
+ """
+ Set the timeout of the sandbox.
+ After the timeout expires the sandbox will be automatically killed.
+ This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to `.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.
+
+ :param timeout: Timeout for the sandbox in **seconds**
+ :param request_timeout: Timeout for the request in **seconds**
+ """
+ ...
@overload
@staticmethod
@@ -283,7 +320,20 @@ class Sandbox(SandboxSetup, SandboxApi):
domain: Optional[str] = None,
debug: Optional[bool] = None,
request_timeout: Optional[float] = None,
- ) -> None: ...
+ ) -> None:
+ """
+ Set the timeout of the sandbox specified by sandbox ID.
+ After the timeout expires the sandbox will be automatically killed.
+ This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to `.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.
+
+ :param sandbox_id: Sandbox ID
+ :param timeout: Timeout for the sandbox in **seconds**
+ :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+ :param request_timeout: Timeout for the request in **seconds**
+ """
+ ...
@class_method_variant("_cls_set_timeout")
def set_timeout( # type: ignore
@@ -291,14 +341,6 @@ class Sandbox(SandboxSetup, SandboxApi):
timeout: int,
request_timeout: Optional[float] = None,
) -> None:
- """
- Set the sandbox's timeout, after which the sandbox will be automatically killed.
- The sandbox can be kept alive for a maximum of 24 hours from the time of creation.
- If you try to set the timeout to a period, which exceeds the maximum limit, the timeout will be set to the maximum limit.
-
- :param timeout: Duration in milliseconds. Must be between 0 and 86400000 milliseconds (24 hours).
- :param request_timeout: Timeout for the request
- """
config_dict = self.connection_config.__dict__
config_dict.pop("access_token", None)
config_dict.pop("api_url", None)