Skip to content

armgit / E2B

Public Imported from GitHub
0

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

[skip ci] Release new versions

github-actions[bot]93134e2faac1
diff --git a/.changeset/small-wolves-cheer.md b/.changeset/small-wolves-cheer.md
deleted file mode 100644
index a182f4a53..000000000
--- a/.changeset/small-wolves-cheer.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-'@e2b/cli': patch
----
-
-updated help link
diff --git a/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/auth/page.mdx b/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/auth/page.mdx
new file mode 100644
index 000000000..2c82afa69
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/auth/page.mdx
@@ -0,0 +1,58 @@
+## e2b auth
+
+
+authentication commands
+
+### Usage
+
+```bash
+e2b auth [options] [command]
+```
+## e2b auth login
+
+
+log in to CLI
+
+### Usage
+
+```bash
+e2b auth login [options]
+```
+
+
+## e2b auth logout
+
+
+log out of CLI
+
+### Usage
+
+```bash
+e2b auth logout [options]
+```
+
+
+## e2b auth info
+
+
+get information about the current user
+
+### Usage
+
+```bash
+e2b auth info [options]
+```
+
+
+## e2b auth configure
+
+
+configure user
+
+### Usage
+
+```bash
+e2b auth configure [options]
+```
+
+
diff --git a/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/sandbox/page.mdx b/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/sandbox/page.mdx
new file mode 100644
index 000000000..53c9a5b35
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/sandbox/page.mdx
@@ -0,0 +1,89 @@
+## e2b sandbox
+
+
+work with sandboxes
+
+### Usage
+
+```bash
+e2b sandbox [options] [command]
+```
+## e2b sandbox connect
+
+
+connect terminal to already running sandbox
+
+### Usage
+
+```bash
+e2b sandbox connect [options] <sandboxID>
+```
+
+
+## e2b sandbox list
+
+
+list all running sandboxes
+
+### Usage
+
+```bash
+e2b sandbox list [options]
+```
+
+
+## e2b sandbox kill
+
+
+kill sandbox
+
+### Usage
+
+```bash
+e2b sandbox kill [options] [sandboxID]
+```
+
+### Options
+
+
+ - `-a, --all: kill all running sandboxes `
+
+
+## e2b sandbox spawn
+
+
+spawn sandbox and connect terminal to it
+
+### Usage
+
+```bash
+e2b sandbox spawn [options] [template]
+```
+
+### Options
+
+
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
+ - `--config <e2b-toml>: specify path to the E2B config toml. By default E2B tries to find ./e2b.toml in root directory. `
+
+
+## e2b sandbox logs
+
+
+show logs for sandbox
+
+### Usage
+
+```bash
+e2b sandbox logs [options] <sandboxID>
+```
+
+### Options
+
+
+ - `--level <level>: filter logs by level (DEBUG, INFO, WARN, ERROR). The logs with the higher levels will be also shown. [default: INFO]`
+ - `-f, --follow: keep streaming logs until the sandbox is closed `
+ - `--format <format>: specify format for printing logs (json, pretty) [default: pretty]`
+ - `--loggers [loggers]: filter logs by loggers. Specify multiple loggers by separating them with a comma. `
+
+
diff --git a/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/template/page.mdx b/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/template/page.mdx
new file mode 100644
index 000000000..d41cd8537
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/sdk-reference/cli/v1.5.1/template/page.mdx
@@ -0,0 +1,134 @@
+## e2b template
+
+
+manage sandbox templates
+
+### Usage
+
+```bash
+e2b template [options] [command]
+```
+## e2b template build
+
+
+build sandbox template defined by ./e2b.Dockerfile or ./Dockerfile in root directory. By default the root directory is the current working directory. This command also creates e2b.toml config.
+
+### Usage
+
+```bash
+e2b template build [options] [template]
+```
+
+### Options
+
+
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
+ - `-d, --dockerfile <file>: specify path to Dockerfile. By default E2B tries to find e2b.Dockerfile or Dockerfile in root directory. `
+ - `-n, --name <template-name>: specify sandbox template name. You can use the template name to start the sandbox with SDK. The template name must be lowercase and contain only letters, numbers, dashes and underscores. `
+ - `-c, --cmd <start-command>: specify command that will be executed when the sandbox is started. `
+ - `--ready-cmd <ready-command>: specify command that will need to exit 0 for the template to be ready. `
+ - `-t, --team <team-id>: specify the team ID that the operation will be associated with. You can find team ID in the team settings in the E2B dashboard (https://e2b.dev/dashboard?tab=team). `
+ - `--config <e2b-toml>: specify path to the E2B config toml. By default E2B tries to find ./e2b.toml in root directory. `
+ - `--cpu-count <cpu-count>: specify the number of CPUs that will be used to run the sandbox. The default value is 2. `
+ - `--memory-mb <memory-mb>: specify the amount of memory in megabytes that will be used to run the sandbox. Must be an even number. The default value is 512. `
+ - `--build-arg <args...>: specify additional build arguments for the build command. The format should be <varname>=<value>. `
+ - `--no-cache: skip cache when building the template. `
+
+
+## e2b template list
+
+
+list sandbox templates
+
+### Usage
+
+```bash
+e2b template list [options]
+```
+
+### Options
+
+
+ - `-t, --team <team-id>: specify the team ID that the operation will be associated with. You can find team ID in the team settings in the E2B dashboard (https://e2b.dev/dashboard?tab=team). `
+
+
+## e2b template init
+
+
+create basic E2B Dockerfile (./e2b.Dockerfile) in root directory. You can then run e2b template build to build sandbox template from this Dockerfile
+
+### Usage
+
+```bash
+e2b template init [options]
+```
+
+### Options
+
+
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
+
+
+## e2b template delete
+
+
+delete sandbox template and e2b.toml config
+
+### Usage
+
+```bash
+e2b template delete [options] [template]
+```
+
+### Options
+
+
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
+ - `--config <e2b-toml>: specify path to the E2B config toml. By default E2B tries to find ./e2b.toml in root directory. `
+ - `-s, --select: select sandbox template from interactive list `
+ - `-t, --team <team-id>: specify the team ID that the operation will be associated with. You can find team ID in the team settings in the E2B dashboard (https://e2b.dev/dashboard?tab=team). `
+ - `-y, --yes: skip manual delete confirmation `
+
+
+## e2b template publish
+
+
+publish sandbox template
+
+### Usage
+
+```bash
+e2b template publish [options] [template]
+```
+
+### Options
+
+
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
+ - `--config <e2b-toml>: specify path to the E2B config toml. By default E2B tries to find ./e2b.toml in root directory. `
+ - `-s, --select: select sandbox template from interactive list `
+ - `-t, --team <team-id>: specify the team ID that the operation will be associated with. You can find team ID in the team settings in the E2B dashboard (https://e2b.dev/dashboard?tab=team). `
+ - `-y, --yes: skip manual publish confirmation `
+
+
+## e2b template unpublish
+
+
+unpublish sandbox template
+
+### Usage
+
+```bash
+e2b template unpublish [options] [template]
+```
+
+### Options
+
+
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
+ - `--config <e2b-toml>: specify path to the E2B config toml. By default E2B tries to find ./e2b.toml in root directory. `
+ - `-s, --select: select sandbox template from interactive list `
+ - `-t, --team <team-id>: specify the team ID that the operation will be associated with. You can find team ID in the team settings in the E2B dashboard (https://e2b.dev/dashboard?tab=team). `
+ - `-y, --yes: skip manual unpublish confirmation `
+
+
diff --git a/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_async/page.mdx b/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_async/page.mdx
index 37c14af02..17bef7413 100644
--- a/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_async/page.mdx
+++ b/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_async/page.mdx
@@ -1,362 +1,289 @@
-## SandboxApi
+## Filesystem
```python
-class SandboxApi(SandboxApiBase)
+class Filesystem()
```
+Module for interacting with the filesystem in the sandbox.
-### list
+
+### read
```python
-@classmethod
-async def list(cls,
- api_key: Optional[str] = None,
- query: Optional[SandboxQuery] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- headers: Optional[Dict[str, str]] = None,
- proxy: Optional[ProxyTypes] = None) -> List[ListedSandbox]
+@overload
+async def read(path: str,
+ format: Literal["text"] = "text",
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> str
```
-List all running sandboxes.
+Read file content as a `str`.
**Arguments**:
-- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `query`: Filter the list of sandboxes, e.g. by metadata `SandboxQuery(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 environments
-- `debug`: Enable debug mode, all requested are then sent to localhost
+- `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**
-- `headers`: Additional headers to send with the request
-- `proxy`: Proxy to use for the request
**Returns**:
-List of running sandboxes
+File content as a `str`
-### get\_info
+### read
```python
-@classmethod
-async def get_info(cls,
- sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- headers: Optional[Dict[str, str]] = None,
- proxy: Optional[ProxyTypes] = None) -> SandboxInfo
+@overload
+async def read(path: str,
+ format: Literal["bytes"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bytearray
```
-Get the sandbox info.
+Read file content as a `bytearray`.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `domain`: Domain to use for the request, defaults to `E2B_DOMAIN` environment variable
-- `debug`: Debug mode, defaults to `E2B_DEBUG` environment variable
+- `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**
-- `headers`: Additional headers to send with the request
-- `proxy`: Proxy to use for the request
**Returns**:
-Sandbox info
-
-
+File content as a `bytearray`
-## AsyncSandbox
+### read
```python
-class AsyncSandbox(SandboxSetup, SandboxApi)
+@overload
+async def read(
+ path: str,
+ format: Literal["stream"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> AsyncIterator[bytes]
```
-E2B cloud sandbox is a secure and isolated cloud environment.
+Read file content as a `AsyncIterator[bytes]`.
-The sandbox allows you to:
-- Access Linux OS
-- Create, list, and delete files and directories
-- Run commands
-- Run isolated code
-- Access the internet
+**Arguments**:
-Check docs [here](https://e2b.dev/docs).
+- `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**
-Use the `AsyncSandbox.create()` to create a new sandbox.
+**Returns**:
-**Example**:
+File content as an `AsyncIterator[bytes]`
-```python
-from e2b import AsyncSandbox
-sandbox = await AsyncSandbox.create()
+### write
+
+```python
+@overload
+async def write(path: str,
+ data: Union[str, bytes, IO],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
+Write content to a file on the path.
-### files
+Writing to a file that doesn't exist creates the file.
-```python
-@property
-def files() -> Filesystem
-```
+Writing to a file that already exists overwrites the file.
-Module for interacting with the sandbox filesystem.
+Writing to a file at path that doesn't exist creates the necessary directories.
+**Arguments**:
-### commands
+- `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**
-```python
-@property
-def commands() -> Commands
-```
+**Returns**:
-Module for running commands in the sandbox.
+Information about the written file
-### pty
+### write
```python
-@property
-def pty() -> Pty
+@overload
+async def write(files: List[WriteEntry],
+ user: Optional[Username] = "user",
+ request_timeout: Optional[float] = None) -> List[EntryInfo]
```
-Module for interacting with the sandbox pseudo-terminal.
+Writes multiple files.
+**Arguments**:
-### sandbox\_id
+- `files`: list of files to write
+- `user`: Run the operation as this user
+- `request_timeout`: Timeout for the request
-```python
-@property
-def sandbox_id() -> str
-```
+**Returns**:
-Unique identifier of the sandbox.
+Information about the written files
-### \_\_init\_\_
+### write
```python
-def __init__(**opts: Unpack[AsyncSandboxOpts])
+async def write(
+ path_or_files: Union[str, List[WriteEntry]],
+ data_or_user: Union[str, bytes, IO, Username] = "user",
+ user_or_request_timeout: Optional[Union[float, Username]] = None,
+ request_timeout_or_none: Optional[float] = None
+) -> Union[EntryInfo, List[EntryInfo]]
```
-Use `AsyncSandbox.create()` to create a new sandbox instead.
+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, you'll get an error.
-### is\_running
+### list
```python
-async def is_running(request_timeout: Optional[float] = None) -> bool
+async def list(path: str,
+ depth: Optional[int] = 1,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> List[EntryInfo]
```
-Check if the sandbox is running.
+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**:
-`True` if the sandbox is running, `False` otherwise
-Example
-```python
-sandbox = await AsyncSandbox.create()
-await sandbox.is_running() # Returns True
-
-await sandbox.kill()
-await sandbox.is_running() # Returns False
-```
+List of entries in the directory
-### create
+### exists
```python
-@classmethod
-async def create(cls,
- template: Optional[str] = None,
- timeout: Optional[int] = None,
- metadata: Optional[Dict[str, str]] = None,
- envs: Optional[Dict[str, str]] = None,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- proxy: Optional[ProxyTypes] = None,
- secure: Optional[bool] = None)
+async def exists(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Create a new sandbox.
-
-By default, the sandbox is created from the default `base` sandbox template.
+Check if a file or a directory exists.
**Arguments**:
-- `template`: Sandbox template name or ID
-- `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.
-- `metadata`: Custom metadata for the sandbox
-- `envs`: Custom environment variables for the sandbox
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `path`: Path to a file or a directory
+- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
-- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
-- `secure`: Envd is secured with access token and cannot be used without it
**Returns**:
-sandbox instance for the new sandbox
-Use this method instead of using the constructor to create a new sandbox.
+`True` if the file or directory exists, `False` otherwise
-### connect
+### remove
```python
-@classmethod
-async def connect(cls,
- sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- proxy: Optional[ProxyTypes] = None)
+async def remove(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> None
```
-Connect to an existing sandbox.
-
-With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
+Remove a file or a directory.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
+- `path`: Path to a file or a directory
+- `user`: Run the operation as this user
+- `request_timeout`: Timeout for the request in **seconds**
-**Returns**:
-sandbox instance for the existing sandbox
-@example
+### rename
+
```python
-sandbox = await AsyncSandbox.create()
-sandbox_id = sandbox.sandbox_id
+async def rename(old_path: str,
+ new_path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
+```
-same_sandbox = await AsyncSandbox.connect(sandbox_id)
+Rename a file or directory.
+**Arguments**:
-### kill
-
-```python
-@overload
-async def kill(request_timeout: Optional[float] = None) -> bool
-```
-
-Kill the sandbox.
-
-**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**:
-`True` if the sandbox was killed, `False` if the sandbox was not found
+Information about the renamed file or directory
-### kill
+### make\_dir
```python
-@overload
-@staticmethod
-async def kill(sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- proxy: Optional[ProxyTypes] = None) -> bool
+async def make_dir(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Kill the sandbox specified by sandbox ID.
+Create a new directory and all directories along the way if needed on the specified path.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `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**
-- `proxy`: Proxy to use for the request
**Returns**:
-`True` if the sandbox was killed, `False` if the sandbox was not found
-
-
-### set\_timeout
-
-```python
-@overload
-async def set_timeout(timeout: int,
- request_timeout: Optional[float] = 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.
-
-**Arguments**:
-
-- `timeout`: Timeout for the sandbox in **seconds**
-- `request_timeout`: Timeout for the request in **seconds**
-
-
-### set\_timeout
-
-```python
-@overload
-@staticmethod
-async def set_timeout(sandbox_id: str,
- timeout: int,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- proxy: Optional[ProxyTypes] = None) -> None
-```
-
-Set the timeout of the specified 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.
-
-**Arguments**:
-
-- `sandbox_id`: Sandbox ID
-- `timeout`: Timeout for the sandbox in **seconds**
-- `request_timeout`: Timeout for the request in **seconds**
-- `proxy`: Proxy to use for the request
+`True` if the directory was created, `False` if the directory already exists
-### get\_info
+### watch\_dir
```python
-async def get_info(request_timeout: Optional[float] = None) -> SandboxInfo
+async def watch_dir(path: str,
+ on_event: OutputHandler[FilesystemEvent],
+ on_exit: Optional[OutputHandler[Exception]] = None,
+ user: Username = "user",
+ request_timeout: Optional[float] = None,
+ timeout: Optional[float] = 60,
+ recursive: bool = False) -> AsyncWatchHandle
```
-Get sandbox information like sandbox ID, template, metadata, started at/end at date.
+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**:
-Sandbox info
-
-
+`AsyncWatchHandle` object for stopping watching directory
@@ -383,289 +310,345 @@ Stop watching the directory.
-## Filesystem
+
+
+## SandboxApi
```python
-class Filesystem()
+class SandboxApi(SandboxApiBase)
```
-Module for interacting with the filesystem in the sandbox.
-
-### read
+### list
```python
-@overload
-async def read(path: str,
- format: Literal["text"] = "text",
- user: Username = "user",
- request_timeout: Optional[float] = None) -> str
+@classmethod
+async def list(cls,
+ api_key: Optional[str] = None,
+ query: Optional[SandboxQuery] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
+ proxy: Optional[ProxyTypes] = None) -> List[ListedSandbox]
```
-Read file content as a `str`.
+List all running sandboxes.
**Arguments**:
-- `path`: Path to the file
-- `user`: Run the operation as this user
-- `format`: Format of the file content—`text` by default
+- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `query`: Filter the list of sandboxes, e.g. by metadata `SandboxQuery(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 environments
+- `debug`: Enable debug mode, all requested are then sent to localhost
- `request_timeout`: Timeout for the request in **seconds**
+- `headers`: Additional headers to send with the request
+- `proxy`: Proxy to use for the request
**Returns**:
-File content as a `str`
+List of running sandboxes
-### read
+### get\_info
```python
-@overload
-async def read(path: str,
- format: Literal["bytes"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bytearray
+@classmethod
+async def get_info(cls,
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
+ proxy: Optional[ProxyTypes] = None) -> SandboxInfo
```
-Read file content as a `bytearray`.
+Get the sandbox info.
**Arguments**:
-- `path`: Path to the file
-- `user`: Run the operation as this user
-- `format`: Format of the file content—`bytes`
+- `sandbox_id`: Sandbox ID
+- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `domain`: Domain to use for the request, defaults to `E2B_DOMAIN` environment variable
+- `debug`: Debug mode, defaults to `E2B_DEBUG` environment variable
- `request_timeout`: Timeout for the request in **seconds**
+- `headers`: Additional headers to send with the request
+- `proxy`: Proxy to use for the request
**Returns**:
-File content as a `bytearray`
+Sandbox info
-### read
+
+
+## Commands
```python
-@overload
-async def read(
- path: str,
- format: Literal["stream"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> AsyncIterator[bytes]
+class Commands()
```
-Read file content as a `AsyncIterator[bytes]`.
+Module for executing commands in the sandbox.
+
+
+### list
+
+```python
+async def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
+```
+
+Lists all running commands and PTY sessions.
**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**
**Returns**:
-File content as an `AsyncIterator[bytes]`
+List of running commands and PTY sessions
-### write
+### kill
```python
-@overload
-async def write(path: str,
- data: Union[str, bytes, IO],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+async def kill(pid: int, request_timeout: Optional[float] = None) -> bool
```
-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.
+Kill a running command specified by its process ID.
-Writing to a file at path that doesn't exist creates the necessary directories.
+It uses `SIGKILL` signal to kill the command.
**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
+- `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**:
-Information about the written file
+`True` if the command was killed, `False` if the command was not found
-### write
+### send\_stdin
```python
-@overload
-async def write(files: List[WriteEntry],
- user: Optional[Username] = "user",
- request_timeout: Optional[float] = None) -> List[EntryInfo]
+async def send_stdin(pid: int,
+ data: str,
+ request_timeout: Optional[float] = None) -> None
```
-Writes multiple files.
-
-**Arguments**:
-
-- `files`: list of files to write
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request
+Send data to command stdin.
-**Returns**:
+: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**
-Information about the written files
-### write
+### run
```python
-async def write(
- path_or_files: Union[str, List[WriteEntry]],
- data_or_user: Union[str, bytes, IO, Username] = "user",
- user_or_request_timeout: Optional[Union[float, Username]] = None,
- request_timeout_or_none: Optional[float] = None
-) -> Union[EntryInfo, List[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, you'll get an error.
+@overload
+async def run(cmd: str,
+ background: Union[Literal[False], None] = None,
+ envs: Optional[Dict[str, str]] = None,
+ user: Username = "user",
+ cwd: Optional[str] = None,
+ on_stdout: Optional[OutputHandler[Stdout]] = None,
+ on_stderr: Optional[OutputHandler[Stderr]] = None,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None) -> CommandResult
+```
+
+Start a new command and wait until it finishes executing.
+**Arguments**:
-### list
+- `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
+- `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
```python
-async def list(path: str,
- depth: Optional[int] = 1,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> List[EntryInfo]
+@overload
+async def run(cmd: str,
+ background: Literal[True],
+ envs: Optional[Dict[str, str]] = None,
+ user: Username = "user",
+ cwd: Optional[str] = None,
+ on_stdout: Optional[OutputHandler[Stdout]] = None,
+ on_stderr: Optional[OutputHandler[Stderr]] = None,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None) -> AsyncCommandHandle
```
-List entries in a directory.
+Start a new command and return a handle to interact with it.
**Arguments**:
-- `path`: Path to the directory
-- `depth`: Depth of the directory to list
-- `user`: Run the operation as this user
+- `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
+- `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**:
-List of entries in the directory
+`AsyncCommandHandle` handle to interact with the running command
-### exists
+### connect
```python
-async def exists(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+async def connect(
+ pid: int,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None,
+ on_stdout: Optional[OutputHandler[Stdout]] = None,
+ on_stderr: Optional[OutputHandler[Stderr]] = None
+) -> AsyncCommandHandle
```
-Check if a file or a directory exists.
+Connects to a running command.
+
+You can use `AsyncCommandHandle.wait()` to wait for the command to finish and get execution results.
**Arguments**:
-- `path`: Path to a file or a directory
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request in **seconds**
+- `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**:
-`True` if the file or directory exists, `False` otherwise
+`AsyncCommandHandle` handle to interact with the running command
+
-### remove
+
+## AsyncCommandHandle
```python
-async def remove(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> None
+class AsyncCommandHandle()
```
-Remove a file or a directory.
+Command execution handle.
-**Arguments**:
+It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
-- `path`: Path to a file or a directory
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request in **seconds**
+### pid
-### rename
+```python
+@property
+def pid()
+```
+
+Command process ID.
+
+
+### stdout
```python
-async def rename(old_path: str,
- new_path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+@property
+def stdout()
```
-Rename a file or directory.
+Command stdout output.
-**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**
+### stderr
-**Returns**:
+```python
+@property
+def stderr()
+```
-Information about the renamed file or directory
+Command stderr output.
-### make\_dir
+### error
```python
-async def make_dir(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+@property
+def error()
```
-Create a new directory and all directories along the way if needed on the specified path.
+Command execution error message.
-**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**
+### exit\_code
-**Returns**:
+```python
+@property
+def exit_code()
+```
-`True` if the directory was created, `False` if the directory already exists
+Command execution exit code.
+`0` if the command finished successfully.
-### watch\_dir
+It is `None` if the command is still running.
+
+
+### disconnect
```python
-async def watch_dir(path: str,
- on_event: OutputHandler[FilesystemEvent],
- on_exit: Optional[OutputHandler[Exception]] = None,
- user: Username = "user",
- request_timeout: Optional[float] = None,
- timeout: Optional[float] = 60,
- recursive: bool = False) -> AsyncWatchHandle
+async def disconnect() -> None
```
-Watch directory for filesystem events.
+Disconnects from the command.
-**Arguments**:
+The command is not killed, but SDK stops receiving events from the command.
+You can reconnect to the command using `sandbox.commands.connect` method.
-- `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
+
+### wait
+
+```python
+async def wait() -> CommandResult
+```
+
+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**:
-`AsyncWatchHandle` object for stopping watching directory
+`CommandResult` result of command execution
+
+
+### kill
+
+```python
+async def kill() -> bool
+```
+
+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
@@ -765,270 +748,287 @@ Call this when the terminal window is resized and the number of columns and rows
-## Commands
+## AsyncSandbox
```python
-class Commands()
+class AsyncSandbox(SandboxSetup, SandboxApi)
```
-Module for executing commands in the sandbox.
+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
-### list
+Check docs [here](https://e2b.dev/docs).
+
+Use the `AsyncSandbox.create()` to create a new sandbox.
+
+**Example**:
```python
-async def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
-```
+from e2b import AsyncSandbox
-Lists all running commands and PTY sessions.
+sandbox = await AsyncSandbox.create()
+```
-**Arguments**:
-- `request_timeout`: Timeout for the request in **seconds**
+### files
-**Returns**:
+```python
+@property
+def files() -> Filesystem
+```
-List of running commands and PTY sessions
+Module for interacting with the sandbox filesystem.
-### kill
+### commands
```python
-async def kill(pid: int, request_timeout: Optional[float] = None) -> bool
+@property
+def commands() -> Commands
```
-Kill a running command specified by its process ID.
+Module for running commands in the sandbox.
-It uses `SIGKILL` signal to kill the command.
-**Arguments**:
+### pty
-- `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**:
+```python
+@property
+def pty() -> Pty
+```
-`True` if the command was killed, `False` if the command was not found
+Module for interacting with the sandbox pseudo-terminal.
-### send\_stdin
+### sandbox\_id
```python
-async def send_stdin(pid: int,
- data: str,
- request_timeout: Optional[float] = None) -> None
+@property
+def sandbox_id() -> str
```
-Send data to command stdin.
+Unique identifier of the sandbox.
-: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**
+### \_\_init\_\_
+
+```python
+def __init__(**opts: Unpack[AsyncSandboxOpts])
+```
+
+Use `AsyncSandbox.create()` to create a new sandbox instead.
-### run
+### is\_running
```python
-@overload
-async def run(cmd: str,
- background: Union[Literal[False], None] = None,
- envs: Optional[Dict[str, str]] = None,
- user: Username = "user",
- cwd: Optional[str] = None,
- on_stdout: Optional[OutputHandler[Stdout]] = None,
- on_stderr: Optional[OutputHandler[Stderr]] = None,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None) -> CommandResult
+async def is_running(request_timeout: Optional[float] = None) -> bool
```
-Start a new command and wait until it finishes executing.
+Check if the sandbox is running.
**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
-- `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
+`True` if the sandbox is running, `False` otherwise
+Example
+```python
+sandbox = await AsyncSandbox.create()
+await sandbox.is_running() # Returns True
+await sandbox.kill()
+await sandbox.is_running() # Returns False
+```
-### run
+
+### create
```python
-@overload
-async def run(cmd: str,
- background: Literal[True],
- envs: Optional[Dict[str, str]] = None,
- user: Username = "user",
- cwd: Optional[str] = None,
- on_stdout: Optional[OutputHandler[Stdout]] = None,
- on_stderr: Optional[OutputHandler[Stderr]] = None,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None) -> AsyncCommandHandle
+@classmethod
+async def create(cls,
+ template: Optional[str] = None,
+ timeout: Optional[int] = None,
+ metadata: Optional[Dict[str, str]] = None,
+ envs: Optional[Dict[str, str]] = None,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ proxy: Optional[ProxyTypes] = None,
+ secure: Optional[bool] = None)
```
-Start a new command and return a handle to interact with it.
+Create a new sandbox.
+
+By default, the sandbox is created from the default `base` sandbox template.
**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
-- `timeout`: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time
+- `template`: Sandbox template name or ID
+- `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.
+- `metadata`: Custom metadata for the sandbox
+- `envs`: Custom environment variables for the sandbox
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
- `request_timeout`: Timeout for the request in **seconds**
+- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
+- `secure`: Envd is secured with access token and cannot be used without it
**Returns**:
-`AsyncCommandHandle` handle to interact with the running command
+sandbox instance for the new sandbox
+Use this method instead of using the constructor to create a new sandbox.
### connect
```python
-async def connect(
- pid: int,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None,
- on_stdout: Optional[OutputHandler[Stdout]] = None,
- on_stderr: Optional[OutputHandler[Stderr]] = None
-) -> AsyncCommandHandle
+@classmethod
+async def connect(cls,
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ proxy: Optional[ProxyTypes] = None)
```
-Connects to a running command.
+Connect to an existing sandbox.
-You can use `AsyncCommandHandle.wait()` to wait for the command to finish and get execution results.
+With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
**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
+- `sandbox_id`: Sandbox ID
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
**Returns**:
-`AsyncCommandHandle` handle to interact with the running command
-
-
-
-
-## AsyncCommandHandle
-
+sandbox instance for the existing sandbox
+@example
```python
-class AsyncCommandHandle()
-```
-
-Command execution handle.
+sandbox = await AsyncSandbox.create()
+sandbox_id = sandbox.sandbox_id
-It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
+same_sandbox = await AsyncSandbox.connect(sandbox_id)
-### pid
+### kill
```python
-@property
-def pid()
+@overload
+async def kill(request_timeout: Optional[float] = None) -> bool
```
-Command process ID.
+Kill the sandbox.
+**Arguments**:
-### stdout
+- `request_timeout`: Timeout for the request in **seconds**
-```python
-@property
-def stdout()
-```
+**Returns**:
-Command stdout output.
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### stderr
+### kill
```python
-@property
-def stderr()
+@overload
+@staticmethod
+async def kill(sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ proxy: Optional[ProxyTypes] = None) -> bool
```
-Command stderr output.
+Kill the sandbox specified by sandbox ID.
+**Arguments**:
-### error
+- `sandbox_id`: Sandbox ID
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `request_timeout`: Timeout for the request in **seconds**
+- `proxy`: Proxy to use for the request
-```python
-@property
-def error()
-```
+**Returns**:
-Command execution error message.
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### exit\_code
+### set\_timeout
```python
-@property
-def exit_code()
+@overload
+async def set_timeout(timeout: int,
+ request_timeout: Optional[float] = None) -> None
```
-Command execution exit code.
-
-`0` if the command finished successfully.
-
-It is `None` if the command is still running.
-
+Set the timeout of the sandbox.
-### disconnect
+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`.
-```python
-async def disconnect() -> None
-```
+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.
-Disconnects from the command.
+**Arguments**:
-The command is not killed, but SDK stops receiving events from the command.
-You can reconnect to the command using `sandbox.commands.connect` method.
+- `timeout`: Timeout for the sandbox in **seconds**
+- `request_timeout`: Timeout for the request in **seconds**
-### wait
+### set\_timeout
```python
-async def wait() -> CommandResult
+@overload
+@staticmethod
+async def set_timeout(sandbox_id: str,
+ timeout: int,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ proxy: Optional[ProxyTypes] = None) -> None
```
-Wait for the command to finish and return the result.
+Set the timeout of the specified sandbox.
-If the command exits with a non-zero exit code, it throws a `CommandExitException`.
+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`.
-**Returns**:
+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.
-`CommandResult` result of command execution
+**Arguments**:
+
+- `sandbox_id`: Sandbox ID
+- `timeout`: Timeout for the sandbox in **seconds**
+- `request_timeout`: Timeout for the request in **seconds**
+- `proxy`: Proxy to use for the request
-### kill
+### get\_info
```python
-async def kill() -> bool
+async def get_info(request_timeout: Optional[float] = None) -> SandboxInfo
```
-Kills the command.
+Get sandbox information like sandbox ID, template, metadata, started at/end at date.
-It uses `SIGKILL` signal to kill the command
+**Arguments**:
+
+- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-`True` if the command was killed successfully, `False` if the command was not found
+Sandbox info
diff --git a/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_sync/page.mdx b/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_sync/page.mdx
index 9d6dcbdcb..56608e109 100644
--- a/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_sync/page.mdx
+++ b/apps/web/src/app/(docs)/docs/sdk-reference/python-sdk/v1.5.2/sandbox_sync/page.mdx
@@ -1,366 +1,269 @@
-## SandboxApi
+## Filesystem
```python
-class SandboxApi(SandboxApiBase)
+class Filesystem()
```
+Module for interacting with the filesystem in the sandbox.
-### list
+
+### read
```python
-@classmethod
-def list(cls,
- api_key: Optional[str] = None,
- query: Optional[SandboxQuery] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- headers: Optional[Dict[str, str]] = None,
- proxy: Optional[ProxyTypes] = None) -> List[ListedSandbox]
+@overload
+def read(path: str,
+ format: Literal["text"] = "text",
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> str
```
-List all running sandboxes.
+Read file content as a `str`.
**Arguments**:
-- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `query`: Filter the list of sandboxes, e.g. by metadata `SandboxQuery(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 environments
-- `debug`: Enable debug mode, all requested are then sent to localhost
+- `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**
-- `headers`: Additional headers to send with the request
-- `proxy`: Proxy to use for the request
**Returns**:
-List of running sandboxes
+File content as a `str`
-### get\_info
+### read
```python
-@classmethod
-def get_info(cls,
- sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- headers: Optional[Dict[str, str]] = None,
- proxy: Optional[ProxyTypes] = None) -> SandboxInfo
+@overload
+def read(path: str,
+ format: Literal["bytes"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bytearray
```
-Get the sandbox info.
+Read file content as a `bytearray`.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `domain`: Domain to use for the request, defaults to `E2B_DOMAIN` environment variable
-- `debug`: Debug mode, defaults to `E2B_DEBUG` environment variable
+- `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**
-- `headers`: Additional headers to send with the request
**Returns**:
-Sandbox info
-
-
-
-
-## Sandbox
-
-```python
-class Sandbox(SandboxSetup, SandboxApi)
-```
-
-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](https://e2b.dev/docs).
-
-Use the `Sandbox()` to create a new sandbox.
-
-**Example**:
-
-```python
-from e2b import Sandbox
-
-sandbox = Sandbox()
-```
-
-
-### files
-
-```python
-@property
-def files() -> Filesystem
-```
-
-Module for interacting with the sandbox filesystem.
+File content as a `bytearray`
-### commands
+### read
```python
-@property
-def commands() -> Commands
+@overload
+def read(path: str,
+ format: Literal["stream"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> Iterator[bytes]
```
-Module for running commands in the sandbox.
+Read file content as a `Iterator[bytes]`.
+**Arguments**:
-### pty
+- `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**
-```python
-@property
-def pty() -> Pty
-```
+**Returns**:
-Module for interacting with the sandbox pseudo-terminal.
+File content as an `Iterator[bytes]`
-### sandbox\_id
+### write
```python
-@property
-def sandbox_id() -> str
+@overload
+def write(path: str,
+ data: Union[str, bytes, IO],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
-Unique identifier of the sandbox
-
-
-### \_\_init\_\_
+Write content to a file on the path.
-```python
-def __init__(template: Optional[str] = None,
- timeout: Optional[int] = None,
- metadata: Optional[Dict[str, str]] = None,
- envs: Optional[Dict[str, str]] = None,
- secure: Optional[bool] = None,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- sandbox_id: Optional[str] = None,
- request_timeout: Optional[float] = None,
- proxy: Optional[ProxyTypes] = None)
-```
+Writing to a file that doesn't exist creates the file.
-Create a new sandbox.
+Writing to a file that already exists overwrites the file.
-By default, the sandbox is created from the default `base` sandbox template.
+Writing to a file at path that doesn't exist creates the necessary directories.
**Arguments**:
-- `template`: Sandbox template name or ID
-- `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
-- `metadata`: Custom metadata for the sandbox
-- `envs`: Custom environment variables for the sandbox
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `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**
-- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
**Returns**:
-sandbox instance for the new sandbox
+Information about the written file
-### is\_running
+### write
```python
-def is_running(request_timeout: Optional[float] = None) -> bool
+@overload
+def write(files: List[WriteEntry],
+ user: Optional[Username] = "user",
+ request_timeout: Optional[float] = None) -> List[EntryInfo]
```
-Check if the sandbox is running.
+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 that's in a directory that doesn't exist, you'll get an error.
**Arguments**:
-- `request_timeout`: Timeout for the request in **seconds**
+- `files`: list of files to write
+- `user`: Run the operation as this user
+- `request_timeout`: Timeout for the request
**Returns**:
-`True` if the sandbox is running, `False` otherwise
-Example
-```python
-sandbox = Sandbox()
-sandbox.is_running() # Returns True
-
-sandbox.kill()
-sandbox.is_running() # Returns False
-```
+Information about the written files
-### connect
+### list
```python
-@classmethod
-def connect(cls,
- sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- proxy: Optional[ProxyTypes] = None)
+def list(path: str,
+ depth: Optional[int] = 1,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> List[EntryInfo]
```
-Connects to an existing Sandbox.
-
-With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
+List entries in a directory.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
+- `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**:
-sandbox instance for the existing sandbox
-@example
-```python
-sandbox = Sandbox()
-sandbox_id = sandbox.sandbox_id
-
-same_sandbox = Sandbox.connect(sandbox_id)
-```
+List of entries in the directory
-### kill
+### exists
```python
-@overload
-def kill(request_timeout: Optional[float] = None) -> bool
+def exists(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Kill the sandbox.
+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 sandbox was killed, `False` if the sandbox was not found
+`True` if the file or directory exists, `False` otherwise
-### kill
+### remove
```python
-@overload
-@staticmethod
-def kill(sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- proxy: Optional[ProxyTypes] = None) -> bool
+def remove(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> None
```
-Kill the sandbox specified by sandbox ID.
+Remove a file or a directory.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `path`: Path to a file or a directory
+- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
-- `proxy`: Proxy to use for the request
-
-**Returns**:
-
-`True` if the sandbox was killed, `False` if the sandbox was not found
-### kill
+### rename
```python
-@class_method_variant("_cls_kill")
-def kill(request_timeout: Optional[float] = None) -> bool
+def rename(old_path: str,
+ new_path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
-Kill the sandbox.
+Rename a file or directory.
**Arguments**:
-- `request_timeout`: Timeout for the request
+- `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**:
-`True` if the sandbox was killed, `False` if the sandbox was not found
+Information about the renamed file or directory
-### set\_timeout
+### make\_dir
```python
-@overload
-def set_timeout(timeout: int, request_timeout: Optional[float] = None) -> None
+def make_dir(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-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.
+Create a new directory and all directories along the way if needed on the specified path.
**Arguments**:
-- `timeout`: Timeout for the sandbox in **seconds**
+- `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**:
-### set\_timeout
-
-```python
-@overload
-@staticmethod
-def set_timeout(sandbox_id: str,
- timeout: int,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None,
- proxy: Optional[ProxyTypes] = 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.
-
-**Arguments**:
-
-- `sandbox_id`: Sandbox ID
-- `timeout`: Timeout for the sandbox in **seconds**
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `request_timeout`: Timeout for the request in **seconds**
-- `proxy`: Proxy to use for the request
+`True` if the directory was created, `False` if the directory already exists
-### get\_info
+### watch\_dir
```python
-def get_info(request_timeout: Optional[float] = None) -> SandboxInfo
+def watch_dir(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None,
+ recursive: bool = False) -> WatchHandle
```
-Get sandbox information like sandbox ID, template, metadata, started at/end at date.
+Watch directory for filesystem events.
**Arguments**:
+- `path`: Path to a directory to watch
+- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
+- `recursive`: Watch directory recursively
**Returns**:
-Sandbox info
+`WatchHandle` object for stopping watching directory
@@ -402,269 +305,309 @@ List of filesystem events
-## Filesystem
+## SandboxApi
```python
-class Filesystem()
+class SandboxApi(SandboxApiBase)
```
-Module for interacting with the filesystem in the sandbox.
+### list
-### read
+```python
+@classmethod
+def list(cls,
+ api_key: Optional[str] = None,
+ query: Optional[SandboxQuery] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
+ proxy: Optional[ProxyTypes] = None) -> List[ListedSandbox]
+```
+
+List all running sandboxes.
+
+**Arguments**:
+
+- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `query`: Filter the list of sandboxes, e.g. by metadata `SandboxQuery(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 environments
+- `debug`: Enable debug mode, all requested are then sent to localhost
+- `request_timeout`: Timeout for the request in **seconds**
+- `headers`: Additional headers to send with the request
+- `proxy`: Proxy to use for the request
+
+**Returns**:
+
+List of running sandboxes
+
+
+### get\_info
```python
-@overload
-def read(path: str,
- format: Literal["text"] = "text",
- user: Username = "user",
- request_timeout: Optional[float] = None) -> str
+@classmethod
+def get_info(cls,
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
+ proxy: Optional[ProxyTypes] = None) -> SandboxInfo
```
-Read file content as a `str`.
+Get the sandbox info.
**Arguments**:
-- `path`: Path to the file
-- `user`: Run the operation as this user
-- `format`: Format of the file content—`text` by default
+- `sandbox_id`: Sandbox ID
+- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `domain`: Domain to use for the request, defaults to `E2B_DOMAIN` environment variable
+- `debug`: Debug mode, defaults to `E2B_DEBUG` environment variable
- `request_timeout`: Timeout for the request in **seconds**
+- `headers`: Additional headers to send with the request
**Returns**:
-File content as a `str`
+Sandbox info
-### read
+
+
+## Commands
```python
-@overload
-def read(path: str,
- format: Literal["bytes"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bytearray
+class Commands()
```
-Read file content as a `bytearray`.
+Module for executing commands in the sandbox.
+
+
+### list
+
+```python
+def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
+```
+
+Lists all running commands and PTY sessions.
**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**
**Returns**:
-File content as a `bytearray`
+List of running commands and PTY sessions
-### read
+### kill
```python
-@overload
-def read(path: str,
- format: Literal["stream"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> Iterator[bytes]
+def kill(pid: int, request_timeout: Optional[float] = None) -> bool
```
-Read file content as a `Iterator[bytes]`.
+Kills a running command specified by its process ID.
+
+It uses `SIGKILL` signal to kill the command.
**Arguments**:
-- `path`: Path to the file
-- `user`: Run the operation as this user
-- `format`: Format of the file content—`stream`
+- `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**:
-File content as an `Iterator[bytes]`
+`True` if the command was killed, `False` if the command was not found
-### write
+### send\_stdin
```python
-@overload
-def write(path: str,
- data: Union[str, bytes, IO],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+def send_stdin(pid: int, data: str, request_timeout: Optional[float] = None)
```
-Write content to a file on the path.
+Send data to command stdin.
-Writing to a file that doesn't exist creates the file.
+: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**
-Writing to a file that already exists overwrites the file.
-Writing to a file at path that doesn't exist creates the necessary directories.
+
+### run
+
+```python
+@overload
+def run(cmd: str,
+ background: Union[Literal[False], None] = None,
+ envs: Optional[Dict[str, str]] = None,
+ user: Username = "user",
+ cwd: Optional[str] = None,
+ on_stdout: Optional[Callable[[str], None]] = None,
+ on_stderr: Optional[Callable[[str], None]] = None,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None) -> CommandResult
+```
+
+Start a new command and wait until it finishes executing.
**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
+- `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
+- `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**:
-Information about the written file
+`CommandResult` result of the command execution
-### write
+### run
```python
@overload
-def write(files: List[WriteEntry],
- user: Optional[Username] = "user",
- request_timeout: Optional[float] = None) -> List[EntryInfo]
+def run(cmd: str,
+ background: Literal[True],
+ envs: Optional[Dict[str, str]] = None,
+ user: Username = "user",
+ cwd: Optional[str] = None,
+ on_stdout: None = None,
+ on_stderr: None = None,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None) -> CommandHandle
```
-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 that's in a directory that doesn't exist, you'll get an error.
+Start a new command and return a handle to interact with it.
**Arguments**:
-- `files`: list of files to write
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request
+- `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
+- `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**:
-Information about the written files
+`CommandHandle` handle to interact with the running command
-### list
+### connect
```python
-def list(path: str,
- depth: Optional[int] = 1,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> List[EntryInfo]
+def connect(pid: int,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None)
```
-List entries in a directory.
+Connects to a running command.
+
+You can use `CommandHandle.wait()` to wait for the command to finish and get execution results.
**Arguments**:
-- `path`: Path to the directory
-- `depth`: Depth of the directory to list
-- `user`: Run the operation as this user
+- `pid`: Process ID of the command to connect to. You can get the list of processes using `sandbox.commands.list()`
+- `timeout`: Timeout for the connection in **seconds**. Using `0` will not limit the connection time
- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-List of entries in the directory
+`CommandHandle` handle to interact with the running command
+
-### exists
+
+## CommandHandle
```python
-def exists(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+class CommandHandle()
```
-Check if a file or a directory exists.
+Command execution handle.
-**Arguments**:
+It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
-- `path`: Path to a file or a directory
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request in **seconds**
-**Returns**:
+### pid
-`True` if the file or directory exists, `False` otherwise
+```python
+@property
+def pid()
+```
+Command process ID.
-### remove
+
+### \_\_iter\_\_
```python
-def remove(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> None
+def __iter__()
```
-Remove a file or a directory.
+Iterate over the command output.
-**Arguments**:
+**Returns**:
-- `path`: Path to a file or a directory
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request in **seconds**
+Generator of command outputs
-### rename
+### disconnect
```python
-def rename(old_path: str,
- new_path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+def disconnect() -> None
```
-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**:
+Disconnect from the command.
-Information about the renamed file or directory
+The command is not killed, but SDK stops receiving events from the command.
+You can reconnect to the command using `sandbox.commands.connect` method.
-### make\_dir
+### wait
```python
-def make_dir(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+def wait(on_pty: Optional[Callable[[PtyOutput], None]] = None,
+ on_stdout: Optional[Callable[[str], None]] = None,
+ on_stderr: Optional[Callable[[str], None]] = None) -> CommandResult
```
-Create a new directory and all directories along the way if needed on the specified path.
+Wait for the command to finish and returns the result.
+
+If the command exits with a non-zero exit code, it throws a `CommandExitException`.
**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**
+- `on_pty`: Callback for pty output
+- `on_stdout`: Callback for stdout output
+- `on_stderr`: Callback for stderr output
**Returns**:
-`True` if the directory was created, `False` if the directory already exists
+`CommandResult` result of command execution
-### watch\_dir
+### kill
```python
-def watch_dir(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None,
- recursive: bool = False) -> WatchHandle
+def kill() -> bool
```
-Watch directory for filesystem events.
-
-**Arguments**:
+Kills the command.
-- `path`: Path to a directory to watch
-- `user`: Run the operation as this user
-- `request_timeout`: Timeout for the request in **seconds**
-- `recursive`: Watch directory recursively
+It uses `SIGKILL` signal to kill the command.
**Returns**:
-`WatchHandle` object for stopping watching directory
+Whether the command was killed successfully
@@ -761,237 +704,294 @@ Call this when the terminal window is resized and the number of columns and rows
-## Commands
+## Sandbox
+
+```python
+class Sandbox(SandboxSetup, SandboxApi)
+```
+
+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](https://e2b.dev/docs).
+
+Use the `Sandbox()` to create a new sandbox.
+
+**Example**:
+
+```python
+from e2b import Sandbox
+
+sandbox = Sandbox()
+```
+
+
+### files
+
+```python
+@property
+def files() -> Filesystem
+```
+
+Module for interacting with the sandbox filesystem.
+
+
+### commands
```python
-class Commands()
+@property
+def commands() -> Commands
```
-Module for executing commands in the sandbox.
+Module for running commands in the sandbox.
-### list
+### pty
```python
-def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
+@property
+def pty() -> Pty
```
-Lists all running commands and PTY sessions.
+Module for interacting with the sandbox pseudo-terminal.
-**Arguments**:
-- `request_timeout`: Timeout for the request in **seconds**
+### sandbox\_id
-**Returns**:
+```python
+@property
+def sandbox_id() -> str
+```
-List of running commands and PTY sessions
+Unique identifier of the sandbox
-### kill
+### \_\_init\_\_
```python
-def kill(pid: int, request_timeout: Optional[float] = None) -> bool
+def __init__(template: Optional[str] = None,
+ timeout: Optional[int] = None,
+ metadata: Optional[Dict[str, str]] = None,
+ envs: Optional[Dict[str, str]] = None,
+ secure: Optional[bool] = None,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ sandbox_id: Optional[str] = None,
+ request_timeout: Optional[float] = None,
+ proxy: Optional[ProxyTypes] = None)
```
-Kills a running command specified by its process ID.
+Create a new sandbox.
-It uses `SIGKILL` signal to kill the command.
+By default, the sandbox is created from the default `base` sandbox template.
**Arguments**:
-- `pid`: Process ID of the command. You can get the list of processes using `sandbox.commands.list()`
+- `template`: Sandbox template name or ID
+- `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
+- `metadata`: Custom metadata for the sandbox
+- `envs`: Custom environment variables for the sandbox
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
- `request_timeout`: Timeout for the request in **seconds**
+- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
**Returns**:
-`True` if the command was killed, `False` if the command was not found
+sandbox instance for the new sandbox
-### send\_stdin
+### is\_running
```python
-def send_stdin(pid: int, data: str, request_timeout: Optional[float] = None)
+def is_running(request_timeout: Optional[float] = None) -> bool
```
-Send data to command stdin.
+Check if the sandbox is running.
-: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**
+**Arguments**:
+
+- `request_timeout`: Timeout for the request in **seconds**
+**Returns**:
+`True` if the sandbox is running, `False` otherwise
+Example
+```python
+sandbox = Sandbox()
+sandbox.is_running() # Returns True
-### run
+sandbox.kill()
+sandbox.is_running() # Returns False
+```
+
+
+### connect
```python
-@overload
-def run(cmd: str,
- background: Union[Literal[False], None] = None,
- envs: Optional[Dict[str, str]] = None,
- user: Username = "user",
- cwd: Optional[str] = None,
- on_stdout: Optional[Callable[[str], None]] = None,
- on_stderr: Optional[Callable[[str], None]] = None,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None) -> CommandResult
+@classmethod
+def connect(cls,
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ proxy: Optional[ProxyTypes] = None)
```
-Start a new command and wait until it finishes executing.
+Connects to an existing Sandbox.
+
+With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
**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
-- `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**
+- `sandbox_id`: Sandbox ID
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `proxy`: Proxy to use for the request and for the **requests made to the returned sandbox**
**Returns**:
-`CommandResult` result of the command execution
+sandbox instance for the existing sandbox
+@example
+```python
+sandbox = Sandbox()
+sandbox_id = sandbox.sandbox_id
+same_sandbox = Sandbox.connect(sandbox_id)
+```
-### run
+
+### kill
```python
@overload
-def run(cmd: str,
- background: Literal[True],
- envs: Optional[Dict[str, str]] = None,
- user: Username = "user",
- cwd: Optional[str] = None,
- on_stdout: None = None,
- on_stderr: None = None,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None) -> CommandHandle
+def kill(request_timeout: Optional[float] = None) -> bool
```
-Start a new command and return a handle to interact with it.
+Kill the sandbox.
**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
-- `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**:
-`CommandHandle` handle to interact with the running command
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### connect
+### kill
```python
-def connect(pid: int,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None)
+@overload
+@staticmethod
+def kill(sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ proxy: Optional[ProxyTypes] = None) -> bool
```
-Connects to a running command.
-
-You can use `CommandHandle.wait()` to wait for the command to finish and get execution results.
+Kill the sandbox specified by sandbox ID.
**Arguments**:
-- `pid`: Process ID of the command to connect to. You can get the list of processes using `sandbox.commands.list()`
-- `timeout`: Timeout for the connection in **seconds**. Using `0` will not limit the connection time
+- `sandbox_id`: Sandbox ID
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
- `request_timeout`: Timeout for the request in **seconds**
+- `proxy`: Proxy to use for the request
**Returns**:
-`CommandHandle` handle to interact with the running command
-
-
+`True` if the sandbox was killed, `False` if the sandbox was not found
-## CommandHandle
+### kill
```python
-class CommandHandle()
+@class_method_variant("_cls_kill")
+def kill(request_timeout: Optional[float] = None) -> bool
```
-Command execution handle.
-
-It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
+Kill the sandbox.
+**Arguments**:
-### pid
+- `request_timeout`: Timeout for the request
-```python
-@property
-def pid()
-```
+**Returns**:
-Command process ID.
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### \_\_iter\_\_
+### set\_timeout
```python
-def __iter__()
+@overload
+def set_timeout(timeout: int, request_timeout: Optional[float] = None) -> None
```
-Iterate over the command output.
-
-**Returns**:
-
-Generator of command outputs
-
+Set the timeout of the sandbox.
-### disconnect
+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`.
-```python
-def disconnect() -> None
-```
+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.
-Disconnect from the command.
+**Arguments**:
-The command is not killed, but SDK stops receiving events from the command.
-You can reconnect to the command using `sandbox.commands.connect` method.
+- `timeout`: Timeout for the sandbox in **seconds**
+- `request_timeout`: Timeout for the request in **seconds**
-### wait
+### set\_timeout
```python
-def wait(on_pty: Optional[Callable[[PtyOutput], None]] = None,
- on_stdout: Optional[Callable[[str], None]] = None,
- on_stderr: Optional[Callable[[str], None]] = None) -> CommandResult
+@overload
+@staticmethod
+def set_timeout(sandbox_id: str,
+ timeout: int,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ proxy: Optional[ProxyTypes] = None) -> None
```
-Wait for the command to finish and returns the result.
-
-If the command exits with a non-zero exit code, it throws a `CommandExitException`.
+Set the timeout of the sandbox specified by sandbox ID.
-**Arguments**:
+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`.
-- `on_pty`: Callback for pty output
-- `on_stdout`: Callback for stdout output
-- `on_stderr`: Callback for stderr output
+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.
-**Returns**:
+**Arguments**:
-`CommandResult` result of command execution
+- `sandbox_id`: Sandbox ID
+- `timeout`: Timeout for the sandbox in **seconds**
+- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `request_timeout`: Timeout for the request in **seconds**
+- `proxy`: Proxy to use for the request
-### kill
+### get\_info
```python
-def kill() -> bool
+def get_info(request_timeout: Optional[float] = None) -> SandboxInfo
```
-Kills the command.
+Get sandbox information like sandbox ID, template, metadata, started at/end at date.
-It uses `SIGKILL` signal to kill the command.
+**Arguments**:
+
+- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-Whether the command was killed successfully
+Sandbox info
diff --git a/packages/cli/package.json b/packages/cli/package.json
index a96e34151..0251fcccd 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@e2b/cli",
- "version": "1.5.0",
+ "version": "1.5.1",
"description": "CLI for managing e2b sandbox templates",
"homepage": "https://e2b.dev",
"license": "MIT",