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 SDK API reference doc versions

github-actions[bot]7deab37fc152
diff --git a/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/sandbox/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/sandbox/page.mdx
index d4b87498b..53c9a5b35 100644
--- a/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/sandbox/page.mdx
+++ b/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/sandbox/page.mdx
@@ -63,8 +63,8 @@ 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. `
+ - `-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
@@ -81,9 +81,9 @@ 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]`
+ - `--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]`
+ - `--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/api-reference/cli/v1.0.5/template/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/template/page.mdx
index 0958b5fa3..96e83c629 100644
--- a/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/template/page.mdx
+++ b/apps/web/src/app/(docs)/docs/api-reference/cli/v1.0.5/template/page.mdx
@@ -11,7 +11,7 @@ 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.
+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
@@ -22,12 +22,12 @@ 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. `
+ - `-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. `
- `-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. `
+ - `--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>. `
@@ -53,7 +53,7 @@ e2b template list [options]
## 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
+create basic E2B Dockerfile (./e2b.Dockerfile) in root directory. You can then run e2b template build to build sandbox template from this Dockerfile
### Usage
@@ -64,13 +64,13 @@ e2b template init [options]
### Options
- - `-p, --path <path>: change root directory where command is executed to <path> directory `
+ - `-p, --path <path>: change root directory where command is executed to <path> directory `
## e2b template delete
-delete sandbox template and e2b.toml config
+delete sandbox template and e2b.toml config
### Usage
@@ -81,8 +81,8 @@ 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. `
+ - `-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 `
diff --git a/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/charts/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/charts/page.mdx
new file mode 100644
index 000000000..f3176d3b4
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/charts/page.mdx
@@ -0,0 +1,240 @@
+### ChartType
+
+Chart types
+
+#### Enumeration Members
+
+| Enumeration Member | Value |
+| ------ | ------ |
+| `BAR` | `"bar"` |
+| `BOX_AND_WHISKER` | `"box_and_whisker"` |
+| `LINE` | `"line"` |
+| `PIE` | `"pie"` |
+| `SCATTER` | `"scatter"` |
+| `SUPERCHART` | `"superchart"` |
+| `UNKNOWN` | `"unknown"` |
+
+***
+
+### ScaleType
+
+Ax scale types
+
+#### Enumeration Members
+
+| Enumeration Member | Value |
+| ------ | ------ |
+| `ASINH` | `"asinh"` |
+| `CATEGORICAL` | `"categorical"` |
+| `DATETIME` | `"datetime"` |
+| `FUNCTION` | `"function"` |
+| `FUNCTIONLOG` | `"functionlog"` |
+| `LINEAR` | `"linear"` |
+| `LOG` | `"log"` |
+| `LOGIT` | `"logit"` |
+| `SYMLOG` | `"symlog"` |
+
+## Type Aliases
+
+### BarChart
+
+```ts
+type BarChart: Chart2D & object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `elements` | `BarData`[] |
+| `type` | `ChartType.BAR` |
+
+***
+
+### BarData
+
+```ts
+type BarData: object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `group` | `string` |
+| `label` | `string` |
+| `value` | `string` |
+
+***
+
+### BoxAndWhiskerChart
+
+```ts
+type BoxAndWhiskerChart: Chart2D & object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `elements` | `BoxAndWhiskerData`[] |
+| `type` | `ChartType.BOX_AND_WHISKER` |
+
+***
+
+### BoxAndWhiskerData
+
+```ts
+type BoxAndWhiskerData: object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `first_quartile` | `number` |
+| `label` | `string` |
+| `max` | `number` |
+| `median` | `number` |
+| `min` | `number` |
+| `outliers` | `number`[] |
+| `third_quartile` | `number` |
+
+***
+
+### Chart
+
+```ts
+type Chart: object;
+```
+
+Represents a chart.
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `elements` | `any`[] |
+| `title` | `string` |
+| `type` | `ChartType` |
+
+***
+
+### ChartTypes
+
+```ts
+type ChartTypes:
+ | LineChart
+ | ScatterChart
+ | BarChart
+ | PieChart
+ | BoxAndWhiskerChart
+ | SuperChart;
+```
+
+***
+
+### LineChart
+
+```ts
+type LineChart: PointChart & object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `type` | `ChartType.LINE` |
+
+***
+
+### PieChart
+
+```ts
+type PieChart: Chart & object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `elements` | `PieData`[] |
+| `type` | `ChartType.PIE` |
+
+***
+
+### PieData
+
+```ts
+type PieData: object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `angle` | `number` |
+| `label` | `string` |
+| `radius` | `number` |
+
+***
+
+### PointData
+
+```ts
+type PointData: object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `label` | `string` |
+| `points` | [`number` \| `string`, `number` \| `string`][] |
+
+***
+
+### ScatterChart
+
+```ts
+type ScatterChart: PointChart & object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `type` | `ChartType.SCATTER` |
+
+***
+
+### SuperChart
+
+```ts
+type SuperChart: Chart & object;
+```
+
+#### Type declaration
+
+| Name | Type |
+| ------ | ------ |
+| `elements` | `Chart`[] |
+| `type` | `ChartType.SUPERCHART` |
+
+## Functions
+
+### deserializeChart()
+
+```ts
+function deserializeChart(data: any): Chart
+```
+
+#### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `data` | `any` |
+
+#### Returns
+
+`Chart`
diff --git a/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/consts/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/consts/page.mdx
new file mode 100644
index 000000000..d1ee2e76a
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/consts/page.mdx
@@ -0,0 +1,13 @@
+### DEFAULT\_TIMEOUT\_MS
+
+```ts
+const DEFAULT_TIMEOUT_MS: 60000 = 60_000;
+```
+
+***
+
+### JUPYTER\_PORT
+
+```ts
+const JUPYTER_PORT: 49999 = 49999;
+```
diff --git a/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/index/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/index/page.mdx
new file mode 100644
index 000000000..dc55fcc7d
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/index/page.mdx
@@ -0,0 +1,103 @@
+### BarChart
+
+Re-exports BarChart
+
+### BarData
+
+Re-exports BarData
+
+### BoxAndWhiskerChart
+
+Re-exports BoxAndWhiskerChart
+
+### BoxAndWhiskerData
+
+Re-exports BoxAndWhiskerData
+
+### Chart
+
+Re-exports Chart
+
+### ChartType
+
+Re-exports ChartType
+
+### ChartTypes
+
+Re-exports ChartTypes
+
+### Context
+
+Re-exports Context
+
+### CreateCodeContextOpts
+
+Re-exports CreateCodeContextOpts
+
+### default
+
+Renames and re-exports Sandbox
+
+### Execution
+
+Re-exports Execution
+
+### ExecutionError
+
+Re-exports ExecutionError
+
+### LineChart
+
+Re-exports LineChart
+
+### Logs
+
+Re-exports Logs
+
+### MIMEType
+
+Re-exports MIMEType
+
+### OutputMessage
+
+Re-exports OutputMessage
+
+### PieChart
+
+Re-exports PieChart
+
+### PieData
+
+Re-exports PieData
+
+### PointData
+
+Re-exports PointData
+
+### RawData
+
+Re-exports RawData
+
+### Result
+
+Re-exports Result
+
+### RunCodeOpts
+
+Re-exports RunCodeOpts
+
+### Sandbox
+
+Re-exports Sandbox
+
+### ScaleType
+
+Re-exports ScaleType
+
+### ScatterChart
+
+Re-exports ScatterChart
+
+### SuperChart
+
+Re-exports SuperChart
diff --git a/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/messaging/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/messaging/page.mdx
new file mode 100644
index 000000000..e816e6d3c
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/messaging/page.mdx
@@ -0,0 +1,328 @@
+### Execution
+
+Represents the result of a cell execution.
+
+#### Constructors
+
+```ts
+new Execution(
+ results: Result[],
+ logs: Logs,
+ error?: ExecutionError,
+ executionCount?: number): Execution
+```
+
+###### Parameters
+
+| Parameter | Type | Default value | Description |
+| ------ | ------ | ------ | ------ |
+| `results` | `Result`[] | `[]` | List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots). |
+| `logs` | `Logs` | `...` | Logs printed to stdout and stderr during execution. |
+| `error`? | `ExecutionError` | `undefined` | An Error object if an error occurred, null otherwise. |
+| `executionCount`? | `number` | `undefined` | Execution count of the cell. |
+
+###### Returns
+
+`Execution`
+
+#### Properties
+
+| Property | Modifier | Type | Default value | Description |
+| ------ | ------ | ------ | ------ | ------ |
+| `error?` | `public` | `ExecutionError` | `undefined` | An Error object if an error occurred, null otherwise. |
+| `executionCount?` | `public` | `number` | `undefined` | Execution count of the cell. |
+| `logs` | `public` | `Logs` | `undefined` | Logs printed to stdout and stderr during execution. |
+| `results` | `public` | `Result`[] | `[]` | List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots). |
+
+#### Accessors
+
+### text
+
+###### Get Signature
+
+```ts
+get text(): undefined | string
+```
+
+Returns the text representation of the main result of the cell.
+
+###### Returns
+
+`undefined` \| `string`
+
+#### Methods
+
+### toJSON()
+
+```ts
+toJSON(): object
+```
+
+Returns the serializable representation of the execution result.
+
+###### Returns
+
+`object`
+
+| Name | Type |
+| ------ | ------ |
+| `error` | `undefined` \| `ExecutionError` |
+| `logs` | `Logs` |
+| `results` | `Result`[] |
+
+***
+
+### ExecutionError
+
+Represents an error that occurred during the execution of a cell.
+The error contains the name of the error, the value of the error, and the traceback.
+
+#### Constructors
+
+```ts
+new ExecutionError(
+ name: string,
+ value: string,
+ traceback: string): ExecutionError
+```
+
+###### Parameters
+
+| Parameter | Type | Description |
+| ------ | ------ | ------ |
+| `name` | `string` | Name of the error. |
+| `value` | `string` | Value of the error. |
+| `traceback` | `string` | The raw traceback of the error. |
+
+###### Returns
+
+`ExecutionError`
+
+#### Properties
+
+| Property | Modifier | Type | Description |
+| ------ | ------ | ------ | ------ |
+| `name` | `public` | `string` | Name of the error. |
+| `traceback` | `public` | `string` | The raw traceback of the error. |
+| `value` | `public` | `string` | Value of the error. |
+
+***
+
+### OutputMessage
+
+Represents an output message from the sandbox code execution.
+
+#### Constructors
+
+```ts
+new OutputMessage(
+ line: string,
+ timestamp: number,
+ error: boolean): OutputMessage
+```
+
+###### Parameters
+
+| Parameter | Type | Description |
+| ------ | ------ | ------ |
+| `line` | `string` | The output line. |
+| `timestamp` | `number` | Unix epoch in nanoseconds. |
+| `error` | `boolean` | Whether the output is an error. |
+
+###### Returns
+
+`OutputMessage`
+
+#### Properties
+
+| Property | Modifier | Type | Description |
+| ------ | ------ | ------ | ------ |
+| `error` | `readonly` | `boolean` | Whether the output is an error. |
+| `line` | `readonly` | `string` | The output line. |
+| `timestamp` | `readonly` | `number` | Unix epoch in nanoseconds. |
+
+#### Methods
+
+### toString()
+
+```ts
+toString(): string
+```
+
+###### Returns
+
+`string`
+
+***
+
+### Result
+
+Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
+The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
+
+The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
+as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
+for the actual result the representation is always present for the result, the other representations are always optional.
+
+#### Constructors
+
+```ts
+new Result(rawData: RawData, isMainResult: boolean): Result
+```
+
+###### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `rawData` | `RawData` |
+| `isMainResult` | `boolean` |
+
+###### Returns
+
+`Result`
+
+#### Properties
+
+| Property | Modifier | Type | Description |
+| ------ | ------ | ------ | ------ |
+| `chart?` | `readonly` | `ChartTypes` | Contains the chart data. |
+| `data?` | `readonly` | `Record`\<`string`, `unknown`\> | Contains the data from DataFrame. |
+| `extra?` | `readonly` | `any` | Extra data that can be included. Not part of the standard types. |
+| `html?` | `readonly` | `string` | HTML representation of the data. |
+| `isMainResult` | `readonly` | `boolean` | - |
+| `javascript?` | `readonly` | `string` | JavaScript representation of the data. |
+| `jpeg?` | `readonly` | `string` | JPEG representation of the data. |
+| `json?` | `readonly` | `string` | JSON representation of the data. |
+| `latex?` | `readonly` | `string` | LaTeX representation of the data. |
+| `markdown?` | `readonly` | `string` | Markdown representation of the data. |
+| `pdf?` | `readonly` | `string` | PDF representation of the data. |
+| `png?` | `readonly` | `string` | PNG representation of the data. |
+| `raw` | `readonly` | `RawData` | - |
+| `svg?` | `readonly` | `string` | SVG representation of the data. |
+| `text?` | `readonly` | `string` | Text representation of the result. |
+
+#### Methods
+
+### formats()
+
+```ts
+formats(): string[]
+```
+
+Returns all the formats available for the result.
+
+###### Returns
+
+`string`[]
+
+Array of strings representing the formats available for the result.
+
+### toJSON()
+
+```ts
+toJSON(): object
+```
+
+Returns the serializable representation of the result.
+
+###### Returns
+
+`object`
+
+| Name | Type |
+| ------ | ------ |
+| `extra`? | `any` |
+| `html` | `undefined` \| `string` |
+| `javascript` | `undefined` \| `string` |
+| `jpeg` | `undefined` \| `string` |
+| `json` | `undefined` \| `string` |
+| `latex` | `undefined` \| `string` |
+| `markdown` | `undefined` \| `string` |
+| `pdf` | `undefined` \| `string` |
+| `png` | `undefined` \| `string` |
+| `svg` | `undefined` \| `string` |
+| `text` | `undefined` \| `string` |
+
+## Type Aliases
+
+### Logs
+
+```ts
+type Logs: object;
+```
+
+Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.
+
+#### Type declaration
+
+| Name | Type | Description |
+| ------ | ------ | ------ |
+| `stderr` | `string`[] | List of strings printed to stderr by prints, subprocesses, etc. |
+| `stdout` | `string`[] | List of strings printed to stdout by prints, subprocesses, etc. |
+
+***
+
+### MIMEType
+
+```ts
+type MIMEType: string;
+```
+
+Represents a MIME type.
+
+***
+
+### RawData
+
+```ts
+type RawData: object & E2BData;
+```
+
+Dictionary that maps MIME types to their corresponding representations of the data.
+
+## Functions
+
+### extractError()
+
+```ts
+function extractError(res: Response): Promise<undefined | SandboxError>
+```
+
+#### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `res` | `Response` |
+
+#### Returns
+
+`Promise`\<`undefined` \| `SandboxError`\>
+
+***
+
+### parseOutput()
+
+```ts
+function parseOutput(
+ execution: Execution,
+ line: string,
+ onStdout?: (output: OutputMessage) => any,
+ onStderr?: (output: OutputMessage) => any,
+ onResult?: (data: Result) => any,
+onError?: (error: ExecutionError) => any): Promise<void>
+```
+
+#### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `execution` | `Execution` |
+| `line` | `string` |
+| `onStdout`? | (`output`: `OutputMessage`) => `any` |
+| `onStderr`? | (`output`: `OutputMessage`) => `any` |
+| `onResult`? | (`data`: `Result`) => `any` |
+| `onError`? | (`error`: `ExecutionError`) => `any` |
+
+#### Returns
+
+`Promise`\<`void`\>
diff --git a/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/sandbox/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/sandbox/page.mdx
new file mode 100644
index 000000000..96eafec57
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/api-reference/code-interpreter-js-sdk/v1.0.4/sandbox/page.mdx
@@ -0,0 +1,312 @@
+### 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
+
+Check docs here.
+
+Use Sandbox.create to create a new sandbox.
+
+#### Example
+
+```ts
+import { Sandbox } from '@e2b/code-interpreter'
+
+const sandbox = await Sandbox.create()
+```
+
+#### Methods
+
+### createCodeContext()
+
+```ts
+createCodeContext(opts?: CreateCodeContextOpts): Promise<Context>
+```
+
+Creates a new context to run code in.
+
+###### Parameters
+
+| Parameter | Type | Description |
+| ------ | ------ | ------ |
+| `opts`? | `CreateCodeContextOpts` | options for creating the context. |
+
+###### Returns
+
+`Promise`\<`Context`\>
+
+context object.
+
+### runCode()
+
+###### runCode(code, opts)
+
+```ts
+runCode(code: string, opts?: RunCodeOpts & object): Promise<Execution>
+```
+
+Run the code as Python.
+
+Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
+
+You can reference previously defined variables, imports, and functions in the code.
+
+###### Parameters
+
+| Parameter | Type | Description |
+| ------ | ------ | ------ |
+| `code` | `string` | code to execute. |
+| `opts`? | `RunCodeOpts` & `object` | options for executing the code. |
+
+###### Returns
+
+`Promise`\<`Execution`\>
+
+`Execution` result object.
+
+###### runCode(code, opts)
+
+```ts
+runCode(code: string, opts?: RunCodeOpts & object): Promise<Execution>
+```
+
+Run the code for the specified language.
+
+Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
+If no language is specified, Python is used.
+
+You can reference previously defined variables, imports, and functions in the code.
+
+###### Parameters
+
+| Parameter | Type | Description |
+| ------ | ------ | ------ |
+| `code` | `string` | code to execute. |
+| `opts`? | `RunCodeOpts` & `object` | options for executing the code. |
+
+###### Returns
+
+`Promise`\<`Execution`\>
+
+`Execution` result object.
+
+###### runCode(code, opts)
+
+```ts
+runCode(code: string, opts?: RunCodeOpts & object): Promise<Execution>
+```
+
+Runs the code in the specified context, if not specified, the default context is used.
+
+Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
+
+You can reference previously defined variables, imports, and functions in the code.
+
+###### Parameters
+
+| Parameter | Type | Description |
+| ------ | ------ | ------ |
+| `code` | `string` | code to execute. |
+| `opts`? | `RunCodeOpts` & `object` | options for executing the code |
+
+###### Returns
+
+`Promise`\<`Execution`\>
+
+`Execution` result object
+
+## Interfaces
+
+### CreateCodeContextOpts
+
+Options for creating a code context.
+
+#### Properties
+
+### cwd?
+
+```ts
+optional cwd: string;
+```
+
+Working directory for the context.
+
+###### Default
+
+```ts
+/home/user
+```
+
+### language?
+
+```ts
+optional language: string;
+```
+
+Language for the context.
+
+###### Default
+
+```ts
+python
+```
+
+### requestTimeoutMs?
+
+```ts
+optional requestTimeoutMs: number;
+```
+
+Timeout for the request in **milliseconds**.
+
+###### Default
+
+```ts
+30_000 // 30 seconds
+```
+
+***
+
+### RunCodeOpts
+
+Options for running code.
+
+#### Properties
+
+### envs?
+
+```ts
+optional envs: Record<string, string>;
+```
+
+Custom environment variables for code execution.
+
+###### Default
+
+```ts
+{}
+```
+
+### onError()?
+
+```ts
+optional onError: (error: ExecutionError) => any;
+```
+
+Callback for handling the `ExecutionError` object.
+
+###### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `error` | `ExecutionError` |
+
+###### Returns
+
+`any`
+
+### onResult()?
+
+```ts
+optional onResult: (data: Result) => any;
+```
+
+Callback for handling the final execution result.
+
+###### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `data` | `Result` |
+
+###### Returns
+
+`any`
+
+### onStderr()?
+
+```ts
+optional onStderr: (output: OutputMessage) => any;
+```
+
+Callback for handling stderr messages.
+
+###### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `output` | `OutputMessage` |
+
+###### Returns
+
+`any`
+
+### onStdout()?
+
+```ts
+optional onStdout: (output: OutputMessage) => any;
+```
+
+Callback for handling stdout messages.
+
+###### Parameters
+
+| Parameter | Type |
+| ------ | ------ |
+| `output` | `OutputMessage` |
+
+###### Returns
+
+`any`
+
+### requestTimeoutMs?
+
+```ts
+optional requestTimeoutMs: number;
+```
+
+Timeout for the request in **milliseconds**.
+
+###### Default
+
+```ts
+30_000 // 30 seconds
+```
+
+### timeoutMs?
+
+```ts
+optional timeoutMs: number;
+```
+
+Timeout for the code execution in **milliseconds**.
+
+###### Default
+
+```ts
+60_000 // 60 seconds
+```
+
+## Type Aliases
+
+### Context
+
+```ts
+type Context: object;
+```
+
+Represents a context for code execution.
+
+#### Type declaration
+
+| Name | Type | Description |
+| ------ | ------ | ------ |
+| `cwd` | `string` | The working directory of the context. |
+| `id` | `string` | The ID of the context. |
+| `language` | `string` | The language of the context. |
diff --git a/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_async/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_async/page.mdx
index e0973fd00..ef2f8a7ee 100644
--- a/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_async/page.mdx
+++ b/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_async/page.mdx
@@ -1,571 +1,561 @@
-## AsyncWatchHandle
+## SandboxApi
```python
-class AsyncWatchHandle()
+class SandboxApi(SandboxApiBase)
```
-Handle for watching a directory in the sandbox filesystem.
-
-Use `.stop()` to stop watching the directory.
-
-### stop
+### list
```python
-async def stop()
+@classmethod
+async def list(cls,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None) -> List[SandboxInfo]
```
-Stop watching the directory.
+List all running sandboxes.
+**Arguments**:
+- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `request_timeout`: Timeout for the request in **seconds**
+**Returns**:
-## Filesystem
+List of running sandboxes
-```python
-class Filesystem()
-```
-Module for interacting with the filesystem in the sandbox.
-### read
+
+
+## AsyncSandbox
```python
-@overload
-async def read(path: str,
- format: Literal["text"] = "text",
- user: Username = "user",
- request_timeout: Optional[float] = None) -> str
+class AsyncSandbox(SandboxSetup, SandboxApi)
```
-Read file content as a `str`.
+E2B cloud sandbox is a secure and isolated cloud environment.
-**Arguments**:
+The sandbox allows you to:
+- Access Linux OS
+- Create, list, and delete files and directories
+- Run commands
+- Run isolated code
+- Access the internet
-- `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**
+Check docs [here](https://e2b.dev/docs).
-**Returns**:
+Use the `AsyncSandbox.create()` to create a new sandbox.
-File content as a `str`
+**Example**:
+```python
+from e2b import AsyncSandbox
-### read
+sandbox = await AsyncSandbox.create()
+```
+
+
+### files
```python
-@overload
-async def read(path: str,
- format: Literal["bytes"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bytearray
+@property
+def files() -> Filesystem
```
-Read file content as a `bytearray`.
+Module for interacting with the sandbox filesystem.
-**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**
+### commands
-**Returns**:
+```python
+@property
+def commands() -> Commands
+```
-File content as a `bytearray`
+Module for running commands in the sandbox.
-### read
+### pty
```python
-@overload
-async def read(
- path: str,
- format: Literal["stream"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> AsyncIterator[bytes]
+@property
+def pty() -> Pty
```
-Read file content as a `AsyncIterator[bytes]`.
+Module for interacting with the sandbox pseudo-terminal.
-**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**
+### sandbox\_id
-**Returns**:
+```python
+@property
+def sandbox_id() -> str
+```
-File content as an `AsyncIterator[bytes]`
+Unique identifier of the sandbox.
-### write
+### \_\_init\_\_
```python
-async def write(path: str,
- data: Union[str, bytes, IO],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+def __init__(**opts: Unpack[AsyncSandboxOpts])
```
-Write content to a file on the path.
+Use `AsyncSandbox.create()` to create a new sandbox instead.
-Writing to a file that doesn't exist creates the file.
-Writing to a file that already exists overwrites the file.
+### is\_running
-Writing to a file at path that doesn't exist creates the necessary directories.
+```python
+async def is_running(request_timeout: Optional[float] = None) -> bool
+```
+
+Check if the sandbox is running.
**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
- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-Information about the written file
+`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
+### create
```python
-async def list(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> List[EntryInfo]
+@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)
```
-List entries in a directory.
+Create a new sandbox.
+
+By default, the sandbox is created from the default `base` sandbox template.
**Arguments**:
-- `path`: Path to the directory
-- `user`: Run the operation as this user
+- `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**
**Returns**:
-List of entries in the directory
+sandbox instance for the new sandbox
+Use this method instead of using the constructor to create a new sandbox.
-### exists
+### connect
```python
-async def exists(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+@classmethod
+async def connect(cls,
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None)
```
-Check if a file or a directory exists.
+Connect to an existing sandbox.
+
+With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
**Arguments**:
-- `path`: Path to a file or a directory
-- `user`: Run the operation as this user
-- `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
**Returns**:
-`True` if the file or directory exists, `False` otherwise
+sandbox instance for the existing sandbox
+@example
+```python
+sandbox = await AsyncSandbox.create()
+sandbox_id = sandbox.sandbox_id
+same_sandbox = await AsyncSandbox.connect(sandbox_id)
-### remove
+
+### kill
```python
-async def remove(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> None
+@overload
+async def kill(request_timeout: Optional[float] = None) -> bool
```
-Remove a file or a directory.
+Kill the sandbox.
**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
+
-### rename
+### kill
```python
-async def rename(old_path: str,
- new_path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+@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) -> bool
```
-Rename a file or directory.
+Kill the sandbox specified by sandbox ID.
**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
+- `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**
**Returns**:
-Information about the renamed file or directory
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### make\_dir
+### set\_timeout
```python
-async def make_dir(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+@overload
+async def set_timeout(timeout: int,
+ request_timeout: Optional[float] = None) -> None
```
-Create a new directory and all directories along the way if needed on the specified path.
+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**:
-- `path`: Path to a new directory. For example '/dirA/dirB' when creating 'dirB'.
-- `user`: Run the operation as this user
+- `timeout`: Timeout for the sandbox in **seconds**
- `request_timeout`: Timeout for the request in **seconds**
-**Returns**:
-`True` if the directory was created, `False` if the directory already exists
-
-
-### watch\_dir
+### set\_timeout
```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) -> AsyncWatchHandle
+@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) -> None
```
-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
+Set the timeout of the specified sandbox.
-**Returns**:
+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`.
-`AsyncWatchHandle` object for stopping watching directory
+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**
-## SandboxApi
+## AsyncWatchHandle
```python
-class SandboxApi(SandboxApiBase)
+class AsyncWatchHandle()
```
+Handle for watching a directory in the sandbox filesystem.
-### list
-
-```python
-@classmethod
-async def list(cls,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None) -> List[SandboxInfo]
-```
-
-List all running sandboxes.
+Use `.stop()` to stop watching the directory.
-**Arguments**:
-- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `request_timeout`: Timeout for the request in **seconds**
+### stop
-**Returns**:
+```python
+async def stop()
+```
-List of running sandboxes
+Stop watching the directory.
-## Commands
+## Filesystem
```python
-class Commands()
+class Filesystem()
```
-Module for executing commands in the sandbox.
+Module for interacting with the filesystem in the sandbox.
-### list
+### read
```python
-async def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
+@overload
+async def read(path: str,
+ format: Literal["text"] = "text",
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> str
```
-Lists all running commands and PTY sessions.
+Read file content as a `str`.
**Arguments**:
+- `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**
**Returns**:
-List of running commands and PTY sessions
+File content as a `str`
-### kill
+### read
```python
-async def kill(pid: int, request_timeout: Optional[float] = None) -> bool
+@overload
+async def read(path: str,
+ format: Literal["bytes"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bytearray
```
-Kill a running command specified by its process ID.
-
-It uses `SIGKILL` signal to kill the command.
+Read file content as a `bytearray`.
**Arguments**:
-- `pid`: Process ID of the command. You can get the list of processes using `sandbox.commands.list()`
+- `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**:
-`True` if the command was killed, `False` if the command was not found
+File content as a `bytearray`
-### send\_stdin
+### read
```python
-async def send_stdin(pid: int,
- data: str,
- request_timeout: Optional[float] = None) -> None
+@overload
+async def read(
+ path: str,
+ format: Literal["stream"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> AsyncIterator[bytes]
```
-Send data to command stdin.
+Read file content as a `AsyncIterator[bytes]`.
-: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**:
+
+- `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]`
-### run
+### write
```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 write(path: str,
+ data: Union[str, bytes, IO],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
-Start a new command and wait until it finishes executing.
+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.
**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
+- `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**
**Returns**:
-`CommandResult` result of the command execution
+Information about the written file
-### run
+### list
```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
+async def list(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> List[EntryInfo]
```
-Start a new command and return a handle to interact with it.
+List entries in a directory.
**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
+- `path`: Path to the directory
+- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-`AsyncCommandHandle` handle to interact with the running command
+List of entries in the directory
-### connect
+### exists
```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
+async def exists(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Connects to a running command.
-
-You can use `AsyncCommandHandle.wait()` to wait for the command to finish and get execution results.
+Check if a file or a directory exists.
**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
+- `path`: Path to a file or a directory
+- `user`: Run the operation as this user
+- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-`AsyncCommandHandle` handle to interact with the running command
-
-
+`True` if the file or directory exists, `False` otherwise
-## AsyncCommandHandle
+### remove
```python
-class AsyncCommandHandle()
+async def remove(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> None
```
-Command execution handle.
+Remove a file or a directory.
-It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
+**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
+### rename
```python
-@property
-def pid()
+async def rename(old_path: str,
+ new_path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
-Command process ID.
+Rename a file or directory.
+**Arguments**:
-### stdout
+- `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**
-```python
-@property
-def stdout()
-```
-
-Command stdout output.
-
-
-### stderr
-
-```python
-@property
-def stderr()
-```
-
-Command stderr output.
-
-
-### error
-
-```python
-@property
-def error()
-```
-
-Command execution error message.
-
-
-### exit\_code
-
-```python
-@property
-def exit_code()
-```
-
-Command execution exit code.
-
-`0` if the command finished successfully.
+**Returns**:
-It is `None` if the command is still running.
+Information about the renamed file or directory
-### disconnect
+### make\_dir
```python
-async def disconnect() -> None
+async def make_dir(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Disconnects 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.
-
-
-### wait
-
-```python
-async def wait() -> CommandResult
-```
+Create a new directory and all directories along the way if needed on the specified path.
-Wait for the command to finish and return the result.
+**Arguments**:
-If the command exits with a non-zero exit code, it throws a `CommandExitException`.
+- `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**:
-`CommandResult` result of command execution
+`True` if the directory was created, `False` if the directory already exists
-### kill
+### watch\_dir
```python
-async def kill() -> bool
+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) -> AsyncWatchHandle
```
-Kills the command.
+Watch directory for filesystem events.
-It uses `SIGKILL` signal to kill the command
+**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
**Returns**:
-`True` if the command was killed successfully, `False` if the command was not found
+`AsyncWatchHandle` object for stopping watching directory
@@ -665,260 +655,270 @@ Call this when the terminal window is resized and the number of columns and rows
-## AsyncSandbox
+## Commands
```python
-class AsyncSandbox(SandboxSetup, SandboxApi)
+class Commands()
```
-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).
+Module for executing commands in the sandbox.
-Use the `AsyncSandbox.create()` to create a new sandbox.
-**Example**:
+### list
```python
-from e2b import AsyncSandbox
-
-sandbox = await AsyncSandbox.create()
+async def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
```
+Lists all running commands and PTY sessions.
-### files
+**Arguments**:
-```python
-@property
-def files() -> Filesystem
-```
+- `request_timeout`: Timeout for the request in **seconds**
-Module for interacting with the sandbox filesystem.
+**Returns**:
+List of running commands and PTY sessions
-### commands
+
+### kill
```python
-@property
-def commands() -> Commands
+async def kill(pid: int, request_timeout: Optional[float] = None) -> bool
```
-Module for running commands in the sandbox.
+Kill a running command specified by its process ID.
+It uses `SIGKILL` signal to kill the command.
-### pty
+**Arguments**:
-```python
-@property
-def pty() -> 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**
-Module for interacting with the sandbox pseudo-terminal.
+**Returns**:
+
+`True` if the command was killed, `False` if the command was not found
-### sandbox\_id
+### send\_stdin
```python
-@property
-def sandbox_id() -> str
+async def send_stdin(pid: int,
+ data: str,
+ request_timeout: Optional[float] = None) -> None
```
-Unique identifier of the sandbox.
-
-
-### \_\_init\_\_
+Send data to command stdin.
-```python
-def __init__(**opts: Unpack[AsyncSandboxOpts])
-```
+: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**
-Use `AsyncSandbox.create()` to create a new sandbox instead.
-### is\_running
+### run
```python
-async def is_running(request_timeout: Optional[float] = None) -> bool
+@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
```
-Check if the sandbox is running.
+Start a new command and wait until it finishes executing.
**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**:
-`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
-```
+`CommandResult` result of the command execution
-### create
+### run
```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)
+@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
```
-Create a new sandbox.
-
-By default, the sandbox is created from the default `base` sandbox template.
+Start a new command and return a handle to interact with it.
**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
+- `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**:
-sandbox instance for the new sandbox
-Use this method instead of using the constructor to create a new sandbox.
+`AsyncCommandHandle` handle to interact with the running command
### connect
```python
-@classmethod
-async def connect(cls,
- sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None)
+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
```
-Connect to an existing sandbox.
+Connects to a running command.
-With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
+You can use `AsyncCommandHandle.wait()` to wait for the command to finish and get execution results.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `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**:
-sandbox instance for the existing sandbox
-@example
+`AsyncCommandHandle` handle to interact with the running command
+
+
+
+
+## AsyncCommandHandle
+
```python
-sandbox = await AsyncSandbox.create()
-sandbox_id = sandbox.sandbox_id
+class AsyncCommandHandle()
+```
-same_sandbox = await AsyncSandbox.connect(sandbox_id)
+Command execution handle.
+
+It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
-### kill
+### pid
```python
-@overload
-async def kill(request_timeout: Optional[float] = None) -> bool
+@property
+def pid()
```
-Kill the sandbox.
+Command process ID.
-**Arguments**:
-- `request_timeout`: Timeout for the request in **seconds**
+### stdout
-**Returns**:
+```python
+@property
+def stdout()
+```
-`True` if the sandbox was killed, `False` if the sandbox was not found
+Command stdout output.
-### kill
+### stderr
```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) -> bool
+@property
+def stderr()
```
-Kill the sandbox specified by sandbox ID.
+Command stderr output.
-**Arguments**:
-- `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**
+### error
-**Returns**:
+```python
+@property
+def error()
+```
-`True` if the sandbox was killed, `False` if the sandbox was not found
+Command execution error message.
-### set\_timeout
+### exit\_code
```python
-@overload
-async def set_timeout(timeout: int,
- request_timeout: Optional[float] = None) -> None
+@property
+def exit_code()
```
-Set the timeout of the sandbox.
+Command execution exit code.
-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`.
+`0` if the command finished successfully.
-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.
+It is `None` if the command is still running.
-**Arguments**:
-- `timeout`: Timeout for the sandbox in **seconds**
-- `request_timeout`: Timeout for the request in **seconds**
+### disconnect
+```python
+async def disconnect() -> None
+```
-### set\_timeout
+Disconnects 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.
+
+
+### wait
```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) -> None
+async def wait() -> CommandResult
```
-Set the timeout of the specified sandbox.
+Wait for the command to finish and return the result.
-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`.
+If the command exits with a non-zero exit code, it throws a `CommandExitException`.
-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**
-- `request_timeout`: Timeout for the request in **seconds**
+
+### 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
diff --git a/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_sync/page.mdx b/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_sync/page.mdx
index 85edf462c..35d3b0c5e 100644
--- a/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_sync/page.mdx
+++ b/apps/web/src/app/(docs)/docs/api-reference/python-sdk/v1.0.3/sandbox_sync/page.mdx
@@ -1,544 +1,574 @@
-## WatchHandle
+## SandboxApi
```python
-class WatchHandle()
+class SandboxApi(SandboxApiBase)
```
-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.
-
-### stop
+### list
```python
-def stop()
+@classmethod
+def list(cls,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None) -> List[SandboxInfo]
```
-Stop watching the directory.
-After you stop the watcher you won't be able to get the events anymore.
-
-
-### get\_new\_events
+List all running sandboxes.
-```python
-def get_new_events() -> List[FilesystemEvent]
-```
+**Arguments**:
-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.
+- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-List of filesystem events
+List of sandbox info
-## Filesystem
+## Sandbox
```python
-class Filesystem()
+class Sandbox(SandboxSetup, SandboxApi)
```
-Module for interacting with the filesystem in the sandbox.
-
-
-### read
+E2B cloud sandbox is a secure and isolated cloud environment.
-```python
-@overload
-def read(path: str,
- format: Literal["text"] = "text",
- user: Username = "user",
- request_timeout: Optional[float] = None) -> str
-```
+The sandbox allows you to:
+- Access Linux OS
+- Create, list, and delete files and directories
+- Run commands
+- Run isolated code
+- Access the internet
-Read file content as a `str`.
+Check docs [here](https://e2b.dev/docs).
-**Arguments**:
+Use the `Sandbox()` to create a new sandbox.
-- `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**
+**Example**:
-**Returns**:
+```python
+from e2b import Sandbox
-File content as a `str`
+sandbox = Sandbox()
+```
-### read
+### files
```python
-@overload
-def read(path: str,
- format: Literal["bytes"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bytearray
+@property
+def files() -> Filesystem
```
-Read file content as a `bytearray`.
+Module for interacting with the sandbox filesystem.
-**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**
+### commands
-**Returns**:
+```python
+@property
+def commands() -> Commands
+```
-File content as a `bytearray`
+Module for running commands in the sandbox.
-### read
+### pty
```python
-@overload
-def read(path: str,
- format: Literal["stream"],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> Iterator[bytes]
+@property
+def pty() -> Pty
```
-Read file content as a `Iterator[bytes]`.
+Module for interacting with the sandbox pseudo-terminal.
-**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**
+### sandbox\_id
-**Returns**:
+```python
+@property
+def sandbox_id() -> str
+```
-File content as an `Iterator[bytes]`
+Unique identifier of the sandbox
-### write
+### \_\_init\_\_
```python
-def write(path: str,
- data: Union[str, bytes, IO],
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+def __init__(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,
+ sandbox_id: Optional[str] = None,
+ request_timeout: Optional[float] = None)
```
-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.
+Create a new sandbox.
-Writing to a file at path that doesn't exist creates the necessary directories.
+By default, the sandbox is created from the default `base` sandbox template.
**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
+- `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**
**Returns**:
-Information about the written file
+sandbox instance for the new sandbox
-### list
+### is\_running
```python
-def list(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> List[EntryInfo]
+def is_running(request_timeout: Optional[float] = None) -> bool
```
-List entries in a directory.
+Check if the sandbox is running.
**Arguments**:
-- `path`: Path to the directory
-- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-List of entries in the directory
+`True` if the sandbox is running, `False` otherwise
+Example
+```python
+sandbox = Sandbox()
+sandbox.is_running() # Returns True
+
+sandbox.kill()
+sandbox.is_running() # Returns False
+```
-### exists
+### connect
```python
-def exists(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+@classmethod
+def connect(cls,
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None)
```
-Check if a file or a directory exists.
+Connects to an existing Sandbox.
+
+With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
**Arguments**:
-- `path`: Path to a file or a directory
-- `user`: Run the operation as this user
-- `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
**Returns**:
-`True` if the file or directory exists, `False` otherwise
+sandbox instance for the existing sandbox
+@example
+```python
+sandbox = Sandbox()
+sandbox_id = sandbox.sandbox_id
+
+same_sandbox = Sandbox.connect(sandbox_id)
-### remove
+### kill
```python
-def remove(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> None
+@overload
+def kill(request_timeout: Optional[float] = None) -> bool
```
-Remove a file or a directory.
+Kill the sandbox.
**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**:
-### rename
+`True` if the sandbox was killed, `False` if the sandbox was not found
+
+
+### kill
```python
-def rename(old_path: str,
- new_path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> EntryInfo
+@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) -> bool
```
-Rename a file or directory.
+Kill the sandbox specified by sandbox ID.
**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
+- `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**
**Returns**:
-Information about the renamed file or directory
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### make\_dir
+### kill
```python
-def make_dir(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> bool
+@class_method_variant("_cls_kill")
+def kill(request_timeout: Optional[float] = None) -> bool
```
-Create a new directory and all directories along the way if needed on the specified path.
+Kill the sandbox.
**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**
+- `request_timeout`: Timeout for the request
**Returns**:
-`True` if the directory was created, `False` if the directory already exists
+`True` if the sandbox was killed, `False` if the sandbox was not found
-### watch\_dir
+### set\_timeout
```python
-def watch_dir(path: str,
- user: Username = "user",
- request_timeout: Optional[float] = None) -> WatchHandle
+@overload
+def set_timeout(timeout: int, request_timeout: Optional[float] = None) -> None
```
-Watch directory for filesystem events.
+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**:
-- `path`: Path to a directory to watch
-- `user`: Run the operation as this user
+- `timeout`: Timeout for the sandbox in **seconds**
- `request_timeout`: Timeout for the request in **seconds**
-**Returns**:
-`WatchHandle` object for stopping watching directory
+### 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) -> 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.
-## SandboxApi
+**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**
+
+
+
+
+## WatchHandle
```python
-class SandboxApi(SandboxApiBase)
+class WatchHandle()
```
+Handle for watching filesystem events.
+It is used to get the latest events that have occurred in the watched directory.
-### list
+Use `.stop()` to stop watching the directory.
+
+
+### stop
```python
-@classmethod
-def list(cls,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None,
- request_timeout: Optional[float] = None) -> List[SandboxInfo]
+def stop()
```
-List all running sandboxes.
+Stop watching the directory.
+After you stop the watcher you won't be able to get the events anymore.
-**Arguments**:
-- `api_key`: API key to use for authentication, defaults to `E2B_API_KEY` environment variable
-- `request_timeout`: Timeout for the request in **seconds**
+### get\_new\_events
+
+```python
+def get_new_events() -> 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 until now.
**Returns**:
-List of sandbox info
+List of filesystem events
-## Commands
+## Filesystem
```python
-class Commands()
+class Filesystem()
```
-Module for executing commands in the sandbox.
+Module for interacting with the filesystem in the sandbox.
-### list
+### read
```python
-def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
+@overload
+def read(path: str,
+ format: Literal["text"] = "text",
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> str
```
-Lists all running commands and PTY sessions.
+Read file content as a `str`.
**Arguments**:
+- `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**
**Returns**:
-List of running commands and PTY sessions
+File content as a `str`
-### kill
+### read
```python
-def kill(pid: int, request_timeout: Optional[float] = None) -> bool
+@overload
+def read(path: str,
+ format: Literal["bytes"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bytearray
```
-Kills a running command specified by its process ID.
-
-It uses `SIGKILL` signal to kill the command.
+Read file content as a `bytearray`.
**Arguments**:
-- `pid`: Process ID of the command. You can get the list of processes using `sandbox.commands.list()`
+- `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**:
-`True` if the command was killed, `False` if the command was not found
+File content as a `bytearray`
-### send\_stdin
+### read
```python
-def send_stdin(pid: int, data: str, request_timeout: Optional[float] = None)
+@overload
+def read(path: str,
+ format: Literal["stream"],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> Iterator[bytes]
```
-Send data to command stdin.
+Read file content as a `Iterator[bytes]`.
-: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**:
+
+- `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 `Iterator[bytes]`
-### run
+### write
```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
+def write(path: str,
+ data: Union[str, bytes, IO],
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
-Start a new command and wait until it finishes executing.
+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.
**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
+- `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**
**Returns**:
-`CommandResult` result of the command execution
+Information about the written file
-### run
+### list
```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 list(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> List[EntryInfo]
```
-Start a new command and return a handle to interact with it.
+List entries in a directory.
**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
+- `path`: Path to the directory
+- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-`CommandHandle` handle to interact with the running command
+List of entries in the directory
-### connect
+### exists
```python
-def connect(pid: int,
- timeout: Optional[float] = 60,
- request_timeout: Optional[float] = None)
+def exists(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Connects to a running command.
-
-You can use `CommandHandle.wait()` to wait for the command to finish and get execution results.
+Check if a file or a directory exists.
**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
+- `path`: Path to a file or a directory
+- `user`: Run the operation as this user
- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-`CommandHandle` handle to interact with the running command
-
-
+`True` if the file or directory exists, `False` otherwise
-## CommandHandle
+### remove
```python
-class CommandHandle()
+def remove(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> None
```
-Command execution handle.
+Remove a file or a directory.
-It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
+**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
+
+### rename
```python
-@property
-def pid()
+def rename(old_path: str,
+ new_path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> EntryInfo
```
-Command process ID.
-
-
-### \_\_iter\_\_
+Rename a file or directory.
-```python
-def __iter__()
-```
+**Arguments**:
-Iterate over the command output.
+- `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**:
-Generator of command outputs
+Information about the renamed file or directory
-### disconnect
-
-```python
-def disconnect() -> None
-```
-
-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.
-
-
-### wait
+### make\_dir
```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
+def make_dir(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> bool
```
-Wait for the command to finish and returns the result.
-
-If the command exits with a non-zero exit code, it throws a `CommandExitException`.
+Create a new directory and all directories along the way if needed on the specified path.
**Arguments**:
-- `on_pty`: Callback for pty output
-- `on_stdout`: Callback for stdout output
-- `on_stderr`: Callback for stderr output
+- `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**:
-`CommandResult` result of command execution
+`True` if the directory was created, `False` if the directory already exists
-### kill
+### watch\_dir
```python
-def kill() -> bool
+def watch_dir(path: str,
+ user: Username = "user",
+ request_timeout: Optional[float] = None) -> WatchHandle
```
-Kills the command.
+Watch directory for filesystem events.
-It uses `SIGKILL` signal to kill the command.
+**Arguments**:
+
+- `path`: Path to a directory to watch
+- `user`: Run the operation as this user
+- `request_timeout`: Timeout for the request in **seconds**
**Returns**:
-Whether the command was killed successfully
+`WatchHandle` object for stopping watching directory
@@ -635,267 +665,237 @@ Call this when the terminal window is resized and the number of columns and rows
-## Sandbox
+## Commands
```python
-class Sandbox(SandboxSetup, SandboxApi)
+class Commands()
```
-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
+Module for executing commands in the sandbox.
-Check docs [here](https://e2b.dev/docs).
-Use the `Sandbox()` to create a new sandbox.
-
-**Example**:
+### list
```python
-from e2b import Sandbox
-
-sandbox = Sandbox()
+def list(request_timeout: Optional[float] = None) -> List[ProcessInfo]
```
+Lists all running commands and PTY sessions.
-### files
+**Arguments**:
-```python
-@property
-def files() -> Filesystem
-```
+- `request_timeout`: Timeout for the request in **seconds**
-Module for interacting with the sandbox filesystem.
+**Returns**:
+List of running commands and PTY sessions
-### commands
+
+### kill
```python
-@property
-def commands() -> Commands
+def kill(pid: int, request_timeout: Optional[float] = None) -> bool
```
-Module for running commands in the sandbox.
+Kills a running command specified by its process ID.
+It uses `SIGKILL` signal to kill the command.
-### pty
+**Arguments**:
-```python
-@property
-def pty() -> 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**
-Module for interacting with the sandbox pseudo-terminal.
+**Returns**:
+`True` if the command was killed, `False` if the command was not found
-### sandbox\_id
+
+### send\_stdin
```python
-@property
-def sandbox_id() -> str
+def send_stdin(pid: int, data: str, request_timeout: Optional[float] = None)
```
-Unique identifier of the sandbox
+Send data to command stdin.
+
+: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\_\_
+
+### run
```python
-def __init__(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,
- sandbox_id: Optional[str] = None,
- request_timeout: Optional[float] = None)
+@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
```
-Create a new sandbox.
-
-By default, the sandbox is created from the default `base` sandbox template.
+Start a new command and wait until it finishes executing.
**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
+- `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**:
-sandbox instance for the new sandbox
+`CommandResult` result of the command execution
-### is\_running
+### run
```python
-def is_running(request_timeout: Optional[float] = None) -> bool
+@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
```
-Check if the sandbox is running.
+Start a new command and return a handle to interact with it.
**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**:
-`True` if the sandbox is running, `False` otherwise
-Example
-```python
-sandbox = Sandbox()
-sandbox.is_running() # Returns True
-
-sandbox.kill()
-sandbox.is_running() # Returns False
-```
+`CommandHandle` handle to interact with the running command
### connect
```python
-@classmethod
-def connect(cls,
- sandbox_id: str,
- api_key: Optional[str] = None,
- domain: Optional[str] = None,
- debug: Optional[bool] = None)
+def connect(pid: int,
+ timeout: Optional[float] = 60,
+ request_timeout: Optional[float] = None)
```
-Connects to an existing Sandbox.
+Connects to a running command.
-With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
+You can use `CommandHandle.wait()` to wait for the command to finish and get execution results.
**Arguments**:
-- `sandbox_id`: Sandbox ID
-- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+- `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**:
-sandbox instance for the existing sandbox
-@example
-```python
-sandbox = Sandbox()
-sandbox_id = sandbox.sandbox_id
+`CommandHandle` handle to interact with the running command
-same_sandbox = Sandbox.connect(sandbox_id)
-### kill
+
+## CommandHandle
```python
-@overload
-def kill(request_timeout: Optional[float] = None) -> bool
+class CommandHandle()
```
-Kill the sandbox.
+Command execution handle.
-**Arguments**:
+It provides methods for waiting for the command to finish, retrieving stdout/stderr, and killing the command.
-- `request_timeout`: Timeout for the request in **seconds**
-**Returns**:
+### pid
-`True` if the sandbox was killed, `False` if the sandbox was not found
+```python
+@property
+def pid()
+```
+Command process ID.
-### kill
+
+### \_\_iter\_\_
```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) -> bool
+def __iter__()
```
-Kill the sandbox specified by sandbox ID.
-
-**Arguments**:
-
-- `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**
+Iterate over the command output.
**Returns**:
-`True` if the sandbox was killed, `False` if the sandbox was not found
+Generator of command outputs
-### kill
+### disconnect
```python
-@class_method_variant("_cls_kill")
-def kill(request_timeout: Optional[float] = None) -> bool
+def disconnect() -> None
```
-Kill the sandbox.
-
-**Arguments**:
-
-- `request_timeout`: Timeout for the request
-
-**Returns**:
+Disconnect from the command.
-`True` if the sandbox was killed, `False` if the sandbox was not found
+The command is not killed, but SDK stops receiving events from the command.
+You can reconnect to the command using `sandbox.commands.connect` method.
-### set\_timeout
+### wait
```python
-@overload
-def set_timeout(timeout: int, request_timeout: Optional[float] = None) -> None
+def wait(on_pty: Optional[Callable[[PtyOutput], None]] = None,
+ on_stdout: Optional[Callable[[str], None]] = None,
+ on_stderr: Optional[Callable[[str], None]] = None) -> CommandResult
```
-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`.
+Wait for the command to finish and returns the result.
-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.
+If the command exits with a non-zero exit code, it throws a `CommandExitException`.
**Arguments**:
-- `timeout`: Timeout for the sandbox in **seconds**
-- `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**:
-### set\_timeout
+`CommandResult` result of command execution
+
+
+### kill
```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) -> None
+def kill() -> bool
```
-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`.
+Kills the command.
-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.
+It uses `SIGKILL` signal to kill the command.
-**Arguments**:
+**Returns**:
-- `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**
+Whether the command was killed successfully