From 286361a57d1164c1f011d43cab63823ea33c6f18 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 5 May 2025 17:37:50 +0000 Subject: [PATCH 01/16] [skip ci] Release new versions --- .changeset/fluffy-turkeys-promise.md | 6 - js/package.json | 2 +- python/package.json | 2 +- python/pyproject.toml | 2 +- .../v1.5.0/charts/page.mdx | 240 ++++++ .../v1.5.0/consts/page.mdx | 13 + .../v1.5.0/index/page.mdx | 103 +++ .../v1.5.0/messaging/page.mdx | 326 ++++++++ .../v1.5.0/sandbox/page.mdx | 312 ++++++++ .../v1.5.0/sandbox/page.mdx | 722 ++++++++++++++++++ 10 files changed, 1719 insertions(+), 9 deletions(-) delete mode 100644 .changeset/fluffy-turkeys-promise.md create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.0/charts/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.0/consts/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.0/index/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.0/messaging/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.0/sandbox/page.mdx create mode 100644 sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx diff --git a/.changeset/fluffy-turkeys-promise.md b/.changeset/fluffy-turkeys-promise.md deleted file mode 100644 index 77b7b63c..00000000 --- a/.changeset/fluffy-turkeys-promise.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@e2b/code-interpreter-python': minor -'@e2b/code-interpreter': minor ---- - -bump e2b core to 1.4.0 diff --git a/js/package.json b/js/package.json index fb2301ca..27c76fd4 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "1.4.0", + "version": "1.5.0", "packageManager": "pnpm@8.7.6", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", diff --git a/python/package.json b/python/package.json index 5bb17035..cee595b9 100644 --- a/python/package.json +++ b/python/package.json @@ -1,7 +1,7 @@ { "name": "@e2b/code-interpreter-python", "private": true, - "version": "1.4.0", + "version": "1.5.0", "packageManager": "pnpm@8.7.6", "scripts": { "test": "poetry run pytest -n 4 --verbose -x", diff --git a/python/pyproject.toml b/python/pyproject.toml index a1c9f982..d1d859cf 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "1.4.0" +version = "1.5.0" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" diff --git a/sdk-reference/code-interpreter-js-sdk/v1.5.0/charts/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.0/charts/page.mdx new file mode 100644 index 00000000..f3176d3b --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.0/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/sdk-reference/code-interpreter-js-sdk/v1.5.0/consts/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.0/consts/page.mdx new file mode 100644 index 00000000..d1ee2e76 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.0/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/sdk-reference/code-interpreter-js-sdk/v1.5.0/index/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.0/index/page.mdx new file mode 100644 index 00000000..dc55fcc7 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.0/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/sdk-reference/code-interpreter-js-sdk/v1.5.0/messaging/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.0/messaging/page.mdx new file mode 100644 index 00000000..4b3c4ed9 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.0/messaging/page.mdx @@ -0,0 +1,326 @@ +### 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 + +```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 +``` + +#### 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 +``` + +#### 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/sdk-reference/code-interpreter-js-sdk/v1.5.0/sandbox/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.0/sandbox/page.mdx new file mode 100644 index 00000000..96eafec5 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.0/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 +``` + +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 +``` + +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 +``` + +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 +``` + +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; +``` + +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/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx b/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx new file mode 100644 index 00000000..2fbc0e20 --- /dev/null +++ b/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx @@ -0,0 +1,722 @@ + + + + + +## Sandbox + +```python +class Sandbox(BaseSandbox) +``` + +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_code_interpreter import Sandbox + +sandbox = Sandbox() +``` + + +### run\_code + +```python +@overload +def run_code(code: str, + language: Union[Literal["python"], None] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +def run_code(code: str, + language: Optional[str] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +def run_code(code: str, + context: Optional[Context] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> 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. + +**Arguments**: + +- `code`: Code to execute +- `context`: Concrete context to run the code in. If not specified, the default context for the language is used. It's mutually exclusive with the language. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### create\_code\_context + +```python +def create_code_context(cwd: Optional[str] = None, + language: Optional[str] = None, + request_timeout: Optional[float] = None) -> Context +``` + +Creates a new context to run code in. + +**Arguments**: + +- `cwd`: Set the current working directory for the context, defaults to `/home/user` +- `language`: Language of the context. If not specified, defaults to Python +- `request_timeout`: Timeout for the request in **milliseconds** + +**Returns**: + +Context object + + + + + + +## ChartType + +```python +class ChartType(str, enum.Enum) +``` + +Chart types + + +## ScaleType + +```python +class ScaleType(str, enum.Enum) +``` + +Ax scale types + + +## Chart + +```python +class Chart() +``` + +Extracted data from a chart. It's useful for building an interactive charts or custom visualizations. + + + + + + +## OutputMessage + +```python +@dataclass +class OutputMessage() +``` + +Represents an output message from the sandbox code execution. + + +### line + +The output line. + + +### timestamp + +Unix epoch in nanoseconds + + +### error + +Whether the output is an error. + + +## ExecutionError + +```python +@dataclass +class 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. + + +### name + +Name of the error. + + +### value + +Value of the error. + + +### traceback + +The raw traceback of the error. + + +### to\_json + +```python +def to_json() -> str +``` + +Returns the JSON representation of the Error object. + + +## MIMEType + +```python +class MIMEType(str) +``` + +Represents a MIME type. + + +## Result + +```python +@dataclass +class 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. + + +### is\_main\_result + +Whether this data is the result of the cell. Data can be produced by display calls of which can be multiple in a cell. + + +### extra + +Extra data that can be included. Not part of the standard types. + + +### formats + +```python +def formats() -> Iterable[str] +``` + +Returns all available formats of the result. + +**Returns**: + +All available formats of the result in MIME types. + + +### \_\_str\_\_ + +```python +def __str__() -> Optional[str] +``` + +Returns the text representation of the data. + +**Returns**: + +The text representation of the data. + + +### \_repr\_html\_ + +```python +def _repr_html_() -> Optional[str] +``` + +Returns the HTML representation of the data. + +**Returns**: + +The HTML representation of the data. + + +### \_repr\_markdown\_ + +```python +def _repr_markdown_() -> Optional[str] +``` + +Returns the Markdown representation of the data. + +**Returns**: + +The Markdown representation of the data. + + +### \_repr\_svg\_ + +```python +def _repr_svg_() -> Optional[str] +``` + +Returns the SVG representation of the data. + +**Returns**: + +The SVG representation of the data. + + +### \_repr\_png\_ + +```python +def _repr_png_() -> Optional[str] +``` + +Returns the base64 representation of the PNG data. + +**Returns**: + +The base64 representation of the PNG data. + + +### \_repr\_jpeg\_ + +```python +def _repr_jpeg_() -> Optional[str] +``` + +Returns the base64 representation of the JPEG data. + +**Returns**: + +The base64 representation of the JPEG data. + + +### \_repr\_pdf\_ + +```python +def _repr_pdf_() -> Optional[str] +``` + +Returns the PDF representation of the data. + +**Returns**: + +The PDF representation of the data. + + +### \_repr\_latex\_ + +```python +def _repr_latex_() -> Optional[str] +``` + +Returns the LaTeX representation of the data. + +**Returns**: + +The LaTeX representation of the data. + + +### \_repr\_json\_ + +```python +def _repr_json_() -> Optional[dict] +``` + +Returns the JSON representation of the data. + +**Returns**: + +The JSON representation of the data. + + +### \_repr\_javascript\_ + +```python +def _repr_javascript_() -> Optional[str] +``` + +Returns the JavaScript representation of the data. + +**Returns**: + +The JavaScript representation of the data. + + +## Logs + +```python +@dataclass(repr=False) +class Logs() +``` + +Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc. + + +### stdout + +List of strings printed to stdout by prints, subprocesses, etc. + + +### stderr + +List of strings printed to stderr by prints, subprocesses, etc. + + +### to\_json + +```python +def to_json() -> str +``` + +Returns the JSON representation of the Logs object. + + +### serialize\_results + +```python +def serialize_results(results: List[Result]) -> List[Dict[str, str]] +``` + +Serializes the results to JSON. + + +## Execution + +```python +@dataclass(repr=False) +class Execution() +``` + +Represents the result of a cell execution. + + +### results + +List of the result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots). + + +### logs + +Logs printed to stdout and stderr during execution. + + +### error + +Error object if an error occurred, None otherwise. + + +### execution\_count + +Execution count of the cell. + + +### text + +```python +@property +def text() -> Optional[str] +``` + +Returns the text representation of the result. + +**Returns**: + +The text representation of the result. + + +### to\_json + +```python +def to_json() -> str +``` + +Returns the JSON representation of the Execution object. + + +## Context + +```python +@dataclass +class Context() +``` + +Represents a context for code execution. + + +### id + +The ID of the context. + + +### language + +The language of the context. + + +### cwd + +The working directory of the context. + + + + +## AsyncSandbox + +```python +class AsyncSandbox(BaseAsyncSandbox) +``` + +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 `AsyncSandbox.create()` to create a new sandbox. + +**Example**: + +```python +from e2b_code_interpreter import AsyncSandbox +sandbox = await AsyncSandbox.create() +``` + + +### run\_code + +```python +@overload +async def run_code(code: str, + language: Union[Literal["python"], None] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +async def run_code(code: str, + language: Optional[str] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +async def run_code(code: str, + context: Optional[Context] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> 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. + +**Arguments**: + +- `code`: Code to execute +- `context`: Concrete context to run the code in. If not specified, the default context for the language is used. It's mutually exclusive with the language. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### create\_code\_context + +```python +async def create_code_context( + cwd: Optional[str] = None, + language: Optional[str] = None, + request_timeout: Optional[float] = None) -> Context +``` + +Creates a new context to run code in. + +**Arguments**: + +- `cwd`: Set the current working directory for the context, defaults to `/home/user` +- `language`: Language of the context. If not specified, defaults to Python +- `request_timeout`: Timeout for the request in **milliseconds** + +**Returns**: + +Context object + From cbe4a51b14078b05bb003a193f9d4f818f00f185 Mon Sep 17 00:00:00 2001 From: Tomas Valenta Date: Thu, 8 May 2025 01:57:28 -0700 Subject: [PATCH 02/16] Configure code interpreter server idle timeout (#102) * Configure server timeouts * Remove flag * Add changeset --------- Co-authored-by: Jakub Novak --- .changeset/stale-olives-cover.md | 5 +++++ template/start-up.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/stale-olives-cover.md diff --git a/.changeset/stale-olives-cover.md b/.changeset/stale-olives-cover.md new file mode 100644 index 00000000..111d4718 --- /dev/null +++ b/.changeset/stale-olives-cover.md @@ -0,0 +1,5 @@ +--- +'@e2b/code-interpreter-template': patch +--- + +Increase keep alive timeout diff --git a/template/start-up.sh b/template/start-up.sh index fb45f470..735e5811 100644 --- a/template/start-up.sh +++ b/template/start-up.sh @@ -26,7 +26,7 @@ function start_jupyter_server() { sudo echo "${response}" | sudo tee /root/.jupyter/.session_info >/dev/null cd /root/.server/ - /root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors + /root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640 } echo "Starting Code Interpreter server..." From 918ab8e91a62e79838a25a4dd41f49a62ce52ef6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 8 May 2025 09:15:09 +0000 Subject: [PATCH 03/16] [skip ci] Release new versions --- .changeset/stale-olives-cover.md | 5 ----- template/package.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .changeset/stale-olives-cover.md diff --git a/.changeset/stale-olives-cover.md b/.changeset/stale-olives-cover.md deleted file mode 100644 index 111d4718..00000000 --- a/.changeset/stale-olives-cover.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@e2b/code-interpreter-template': patch ---- - -Increase keep alive timeout diff --git a/template/package.json b/template/package.json index b541ecc7..24a4e53e 100644 --- a/template/package.json +++ b/template/package.json @@ -1,5 +1,5 @@ { "name": "@e2b/code-interpreter-template", "private": true, - "version": "0.0.8" + "version": "0.0.9" } From c6dd986b2303cb3b50c629253b172f084d5c7142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Nov=C3=A1k?= Date: Mon, 12 May 2025 15:34:19 +0200 Subject: [PATCH 04/16] Update babel (#103) --- pnpm-lock.yaml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 78e23697..e90731f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,8 +60,8 @@ importers: packages: - '@babel/runtime@7.24.4': - resolution: {integrity: sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA==} + '@babel/runtime@7.27.1': + resolution: {integrity: sha512-1x3D2xEk2fRo3PAhwQwu5UubzgiVWSXTBfWpVd2Mx2AzRqJuDJCsgaDVZ7HB5iGzDW1Hl1sWN2mFyKjmR9uAog==} engines: {node: '>=6.9.0'} '@bufbuild/protobuf@2.2.2': @@ -1129,9 +1129,6 @@ packages: resolution: {integrity: sha512-h80JrZu/MHUZCyHu5ciuoI0+WxsCxzxJTILn6Fs8rxSnFPh+UVHYfeIxK1nVGugMqkfC4vJcBOYbkfkwYK0+gw==} engines: {node: '>= 14.18.0'} - regenerator-runtime@0.14.1: - resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} - regex-recursion@5.1.1: resolution: {integrity: sha512-ae7SBCbzVNrIjgSbh7wMznPcQel1DNlDtzensnFxpiNpXt1U2ju/bHugH422r+4LAVS1FpW1YCwilmnNsjum9w==} @@ -1503,9 +1500,7 @@ packages: snapshots: - '@babel/runtime@7.24.4': - dependencies: - regenerator-runtime: 0.14.1 + '@babel/runtime@7.27.1': {} '@bufbuild/protobuf@2.2.2': {} @@ -1763,14 +1758,14 @@ snapshots: '@manypkg/find-root@1.1.0': dependencies: - '@babel/runtime': 7.24.4 + '@babel/runtime': 7.27.1 '@types/node': 12.20.55 find-up: 4.1.0 fs-extra: 8.1.0 '@manypkg/get-packages@1.1.3': dependencies: - '@babel/runtime': 7.24.4 + '@babel/runtime': 7.27.1 '@changesets/types': 4.1.0 '@manypkg/find-root': 1.1.0 fs-extra: 8.1.0 @@ -2542,8 +2537,6 @@ snapshots: readdirp@4.1.1: {} - regenerator-runtime@0.14.1: {} - regex-recursion@5.1.1: dependencies: regex: 5.1.1 From fae4e6d105b1edee74a1308eebf0081eb87a0866 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 19 May 2025 18:33:50 +0200 Subject: [PATCH 05/16] Python 3.12 support + deps bump (#105) * bump python 3.12 and dependencies * added changeset --- .changeset/clever-berries-shave.md | 5 +++ template/Dockerfile | 2 +- template/requirements.txt | 65 +++++++++++++++--------------- template/test.Dockerfile | 2 +- 4 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 .changeset/clever-berries-shave.md diff --git a/.changeset/clever-berries-shave.md b/.changeset/clever-berries-shave.md new file mode 100644 index 00000000..ee6748b4 --- /dev/null +++ b/.changeset/clever-berries-shave.md @@ -0,0 +1,5 @@ +--- +'@e2b/code-interpreter-template': patch +--- + +python 3.12 support diff --git a/template/Dockerfile b/template/Dockerfile index 199a5cb0..c48f7df9 100644 --- a/template/Dockerfile +++ b/template/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10.14 +FROM python:3.12 RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \ build-essential curl git util-linux jq sudo fonts-noto-cjk diff --git a/template/requirements.txt b/template/requirements.txt index ca87be9a..3d185173 100644 --- a/template/requirements.txt +++ b/template/requirements.txt @@ -1,42 +1,43 @@ # Jupyter server requirements -jupyter-server==2.13.0 -ipykernel==6.29.3 -ipython==8.22.2 +jupyter-server==2.16.0 +ipykernel==6.29.5 +ipython==9.2.0 -orjson==3.9.15 -pandas==1.5.3 -matplotlib==3.9.2 -pillow==10.3.0 +orjson==3.10.18 +pandas==2.2.3 +matplotlib==3.10.3 +pillow==11.2.1 # Latest version for e2b_charts # Other packages -aiohttp==3.10.11 -beautifulsoup4==4.12.3 -bokeh==3.3.4 -gensim==4.3.2 -imageio==2.34.0 -joblib==1.3.2 -librosa==0.10.1 -nltk==3.9 -numpy==1.26.4 -opencv-python==4.9.0.80 -openpyxl==3.1.2 -plotly==5.19.0 -pytest==8.1.0 -python-docx==1.1.0 -pytz==2024.1 -requests==2.32.2 -scikit-image==0.22.0 -scikit-learn==1.5.0 -scipy==1.12.0 +aiohttp==3.11.18 +beautifulsoup4==4.13.4 +bokeh==3.7.3 +gensim==4.3.3 # unmaintained, blocking numpy and scipy bump +imageio==2.37.0 +joblib==1.5.0 +librosa==0.11.0 +nltk==3.9.1 +numpy==1.26.4 # bump blocked by gensim +numba==0.61.2 +opencv-python==4.11.0.86 +openpyxl==3.1.5 +plotly==6.0.1 +pytest==8.3.5 +python-docx==1.1.2 +pytz==2025.2 +requests==2.32.3 +scikit-image==0.25.2 +scikit-learn==1.6.1 +scipy==1.13.1 # bump blocked by gensim seaborn==0.13.2 -soundfile==0.12.1 -spacy==3.7.4 -textblob==0.18.0 +soundfile==0.13.1 +spacy==3.8.2 # doesn't work on 3.13.x +textblob==0.19.0 tornado==6.4.2 -urllib3==1.26.19 -xarray==2024.2.0 +urllib3==2.4.0 +xarray==2025.4.0 xlrd==2.0.1 -sympy==1.12 +sympy==1.14.0 diff --git a/template/test.Dockerfile b/template/test.Dockerfile index f9302081..9a6c2f21 100644 --- a/template/test.Dockerfile +++ b/template/test.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10.14 +FROM python:3.12 ENV JAVA_HOME=/opt/java/openjdk COPY --from=eclipse-temurin:11-jdk $JAVA_HOME $JAVA_HOME From 85b729ffd6adb8cac1548815205710ece382f6f0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 19 May 2025 16:53:42 +0000 Subject: [PATCH 06/16] [skip ci] Release new versions --- .changeset/clever-berries-shave.md | 5 - .../v1.5.0/sandbox/page.mdx | 398 +++++++++--------- template/package.json | 2 +- 3 files changed, 200 insertions(+), 205 deletions(-) delete mode 100644 .changeset/clever-berries-shave.md diff --git a/.changeset/clever-berries-shave.md b/.changeset/clever-berries-shave.md deleted file mode 100644 index ee6748b4..00000000 --- a/.changeset/clever-berries-shave.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@e2b/code-interpreter-template': patch ---- - -python 3.12 support diff --git a/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx b/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx index 2fbc0e20..6bee4003 100644 --- a/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx +++ b/sdk-reference/code-interpreter-python-sdk/v1.5.0/sandbox/page.mdx @@ -3,205 +3,6 @@ -## Sandbox - -```python -class Sandbox(BaseSandbox) -``` - -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_code_interpreter import Sandbox - -sandbox = Sandbox() -``` - - -### run\_code - -```python -@overload -def run_code(code: str, - language: Union[Literal["python"], None] = None, - on_stdout: Optional[OutputHandler[OutputMessage]] = None, - on_stderr: Optional[OutputHandler[OutputMessage]] = None, - on_result: Optional[OutputHandler[Result]] = None, - on_error: Optional[OutputHandler[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None) -> Execution -``` - -Runs 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. - -**Arguments**: - -- `code`: Code to execute -- `language`: Language to use for code execution. If not defined, the default Python context is used. -- `on_stdout`: Callback for stdout messages -- `on_stderr`: Callback for stderr messages -- `on_result`: Callback for the `Result` object -- `on_error`: Callback for the `ExecutionError` object -- `envs`: Custom environment variables -- `timeout`: Timeout for the code execution in **seconds** -- `request_timeout`: Timeout for the request in **seconds** - -**Returns**: - -`Execution` result object - - -### run\_code - -```python -@overload -def run_code(code: str, - language: Optional[str] = None, - on_stdout: Optional[OutputHandler[OutputMessage]] = None, - on_stderr: Optional[OutputHandler[OutputMessage]] = None, - on_result: Optional[OutputHandler[Result]] = None, - on_error: Optional[OutputHandler[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None) -> Execution -``` - -Runs 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. - -**Arguments**: - -- `code`: Code to execute -- `language`: Language to use for code execution. If not defined, the default Python context is used. -- `on_stdout`: Callback for stdout messages -- `on_stderr`: Callback for stderr messages -- `on_result`: Callback for the `Result` object -- `on_error`: Callback for the `ExecutionError` object -- `envs`: Custom environment variables -- `timeout`: Timeout for the code execution in **seconds** -- `request_timeout`: Timeout for the request in **seconds** - -**Returns**: - -`Execution` result object - - -### run\_code - -```python -@overload -def run_code(code: str, - context: Optional[Context] = None, - on_stdout: Optional[OutputHandler[OutputMessage]] = None, - on_stderr: Optional[OutputHandler[OutputMessage]] = None, - on_result: Optional[OutputHandler[Result]] = None, - on_error: Optional[OutputHandler[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None) -> 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. - -**Arguments**: - -- `code`: Code to execute -- `context`: Concrete context to run the code in. If not specified, the default context for the language is used. It's mutually exclusive with the language. -- `on_stdout`: Callback for stdout messages -- `on_stderr`: Callback for stderr messages -- `on_result`: Callback for the `Result` object -- `on_error`: Callback for the `ExecutionError` object -- `envs`: Custom environment variables -- `timeout`: Timeout for the code execution in **seconds** -- `request_timeout`: Timeout for the request in **seconds** - -**Returns**: - -`Execution` result object - - -### create\_code\_context - -```python -def create_code_context(cwd: Optional[str] = None, - language: Optional[str] = None, - request_timeout: Optional[float] = None) -> Context -``` - -Creates a new context to run code in. - -**Arguments**: - -- `cwd`: Set the current working directory for the context, defaults to `/home/user` -- `language`: Language of the context. If not specified, defaults to Python -- `request_timeout`: Timeout for the request in **milliseconds** - -**Returns**: - -Context object - - - - - - -## ChartType - -```python -class ChartType(str, enum.Enum) -``` - -Chart types - - -## ScaleType - -```python -class ScaleType(str, enum.Enum) -``` - -Ax scale types - - -## Chart - -```python -class Chart() -``` - -Extracted data from a chart. It's useful for building an interactive charts or custom visualizations. - - - - - - ## OutputMessage ```python @@ -557,6 +358,8 @@ The working directory of the context. + + ## AsyncSandbox ```python @@ -720,3 +523,200 @@ Creates a new context to run code in. Context object + + + +## ChartType + +```python +class ChartType(str, enum.Enum) +``` + +Chart types + + +## ScaleType + +```python +class ScaleType(str, enum.Enum) +``` + +Ax scale types + + +## Chart + +```python +class Chart() +``` + +Extracted data from a chart. It's useful for building an interactive charts or custom visualizations. + + + + + + +## Sandbox + +```python +class Sandbox(BaseSandbox) +``` + +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_code_interpreter import Sandbox + +sandbox = Sandbox() +``` + + +### run\_code + +```python +@overload +def run_code(code: str, + language: Union[Literal["python"], None] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +def run_code(code: str, + language: Optional[str] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +def run_code(code: str, + context: Optional[Context] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> 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. + +**Arguments**: + +- `code`: Code to execute +- `context`: Concrete context to run the code in. If not specified, the default context for the language is used. It's mutually exclusive with the language. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### create\_code\_context + +```python +def create_code_context(cwd: Optional[str] = None, + language: Optional[str] = None, + request_timeout: Optional[float] = None) -> Context +``` + +Creates a new context to run code in. + +**Arguments**: + +- `cwd`: Set the current working directory for the context, defaults to `/home/user` +- `language`: Language of the context. If not specified, defaults to Python +- `request_timeout`: Timeout for the request in **milliseconds** + +**Returns**: + +Context object + diff --git a/template/package.json b/template/package.json index 24a4e53e..222d0d21 100644 --- a/template/package.json +++ b/template/package.json @@ -1,5 +1,5 @@ { "name": "@e2b/code-interpreter-template", "private": true, - "version": "0.0.9" + "version": "0.0.10" } From 19af07f5ce78c2778dc86984442e4b1215fc4855 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 03:14:25 -0700 Subject: [PATCH 07/16] Bump setuptools in /python in the pip group across 1 directory (#110) Bumps the pip group with 1 update in the /python directory: [setuptools](https://github.com/pypa/setuptools). Updates `setuptools` from 75.3.0 to 78.1.1 - [Release notes](https://github.com/pypa/setuptools/releases) - [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst) - [Commits](https://github.com/pypa/setuptools/compare/v75.3.0...v78.1.1) --- updated-dependencies: - dependency-name: setuptools dependency-version: 78.1.1 dependency-type: indirect dependency-group: pip ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- python/poetry.lock | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/python/poetry.lock b/python/poetry.lock index efda3671..70a17901 100644 --- a/python/poetry.lock +++ b/python/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand. [[package]] name = "anyio" @@ -239,7 +239,7 @@ description = "Cross-platform colored terminal text." optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" groups = ["dev"] -markers = "sys_platform == \"win32\" or platform_system == \"Windows\"" +markers = "platform_system == \"Windows\" or sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -938,25 +938,24 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "setuptools" -version = "75.3.0" +version = "78.1.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" groups = ["dev"] -markers = "python_version == \"3.9\"" files = [ - {file = "setuptools-75.3.0-py3-none-any.whl", hash = "sha256:f2504966861356aa38616760c0f66568e535562374995367b4e69c7143cf6bcd"}, - {file = "setuptools-75.3.0.tar.gz", hash = "sha256:fba5dd4d766e97be1b1681d98712680ae8f2f26d7881245f2ce9e40714f1a686"}, + {file = "setuptools-78.1.1-py3-none-any.whl", hash = "sha256:c3a9c4211ff4c309edb8b8c4f1cbfa7ae324c4ba9f91ff254e3d305b9fd54561"}, + {file = "setuptools-78.1.1.tar.gz", hash = "sha256:fcc17fd9cd898242f6b4adfaca46137a9edef687f43e6f78469692a5e70d851d"}, ] [package.extras] -check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1) ; sys_platform != \"cygwin\"", "ruff (>=0.5.2) ; sys_platform != \"cygwin\""] -core = ["importlib-metadata (>=6) ; python_version < \"3.10\"", "importlib-resources (>=5.10.2) ; python_version < \"3.9\"", "jaraco.collections", "jaraco.functools", "jaraco.text (>=3.7)", "more-itertools", "more-itertools (>=8.8)", "packaging", "packaging (>=24)", "platformdirs (>=4.2.2)", "tomli (>=2.0.1) ; python_version < \"3.11\"", "wheel (>=0.43.0)"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1) ; sys_platform != \"cygwin\"", "ruff (>=0.8.0) ; sys_platform != \"cygwin\""] +core = ["importlib_metadata (>=6) ; python_version < \"3.10\"", "jaraco.functools (>=4)", "jaraco.text (>=3.7)", "more_itertools", "more_itertools (>=8.8)", "packaging (>=24.2)", "platformdirs (>=4.2.2)", "tomli (>=2.0.1) ; python_version < \"3.11\"", "wheel (>=0.43.0)"] cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"] enabler = ["pytest-enabler (>=2.2)"] -test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21) ; python_version >= \"3.9\" and sys_platform != \"cygwin\"", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "jaraco.test (>=5.5)", "packaging (>=23.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-home (>=0.5)", "pytest-perf ; sys_platform != \"cygwin\"", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel (>=0.44.0)"] -type = ["importlib-metadata (>=7.0.2) ; python_version < \"3.10\"", "jaraco.develop (>=7.21) ; sys_platform != \"cygwin\"", "mypy (==1.12.*)", "pytest-mypy"] +test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21) ; python_version >= \"3.9\" and sys_platform != \"cygwin\"", "jaraco.envs (>=2.2)", "jaraco.path (>=3.7.2)", "jaraco.test (>=5.5)", "packaging (>=24.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-home (>=0.5)", "pytest-perf ; sys_platform != \"cygwin\"", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel (>=0.44.0)"] +type = ["importlib_metadata (>=7.0.2) ; python_version < \"3.10\"", "jaraco.develop (>=7.21) ; sys_platform != \"cygwin\"", "mypy (==1.14.*)", "pytest-mypy"] [[package]] name = "six" From 8f381069366c899a6416afcafdd079fb5a3e3801 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 13:27:45 -0700 Subject: [PATCH 08/16] Bump tornado in /template in the pip group across 1 directory (#112) Bumps the pip group with 1 update in the /template directory: [tornado](https://github.com/tornadoweb/tornado). Updates `tornado` from 6.4.2 to 6.5.1 - [Changelog](https://github.com/tornadoweb/tornado/blob/master/docs/releases.rst) - [Commits](https://github.com/tornadoweb/tornado/compare/v6.4.2...v6.5.1) --- updated-dependencies: - dependency-name: tornado dependency-version: 6.5.1 dependency-type: direct:production dependency-group: pip ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- template/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/requirements.txt b/template/requirements.txt index 3d185173..3adbfdb5 100644 --- a/template/requirements.txt +++ b/template/requirements.txt @@ -36,7 +36,7 @@ seaborn==0.13.2 soundfile==0.13.1 spacy==3.8.2 # doesn't work on 3.13.x textblob==0.19.0 -tornado==6.4.2 +tornado==6.5.1 urllib3==2.4.0 xarray==2025.4.0 xlrd==2.0.1 From e9e0903a4070eb21b2e2fe2473c5e23f47336936 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Wed, 28 May 2025 14:53:18 +0200 Subject: [PATCH 09/16] Updated JavaScript kernel with typescript, top-level async/await, es module import, promise resolution (#111) * e2b ijavascript kernel * removed compiler step * e2b ijavascript * removed ts compiler from dockerfile * removed tests that should no longer be failing * added changeset --- .changeset/breezy-bananas-lay.md | 5 ++++ js/tests/defaultKernels.test.ts | 7 ----- .../tests/async/test_async_default_kernels.py | 8 ------ python/tests/sync/test_default_kernels.py | 5 ---- template/.ts.swcrc | 15 ----------- template/Dockerfile | 6 +---- template/server/messaging.py | 26 ------------------- template/test.Dockerfile | 6 +---- 8 files changed, 7 insertions(+), 71 deletions(-) create mode 100644 .changeset/breezy-bananas-lay.md delete mode 100644 template/.ts.swcrc diff --git a/.changeset/breezy-bananas-lay.md b/.changeset/breezy-bananas-lay.md new file mode 100644 index 00000000..c7d185b0 --- /dev/null +++ b/.changeset/breezy-bananas-lay.md @@ -0,0 +1,5 @@ +--- +'@e2b/code-interpreter-template': patch +--- + +updated ijavascript kernel in the template diff --git a/js/tests/defaultKernels.test.ts b/js/tests/defaultKernels.test.ts index 5750644a..41bc245b 100644 --- a/js/tests/defaultKernels.test.ts +++ b/js/tests/defaultKernels.test.ts @@ -16,10 +16,3 @@ sandboxTest('test ts kernel', async ({ sandbox }) => { ) expect(output.logs.stdout).toEqual(['Hello World!\n']) }) - -sandboxTest('test ts kernel errors', async ({ sandbox }) => { - const output = await sandbox.runCode('import x from "module";', { - language: 'typescript', - }) - expect(output.error?.name).toEqual('TypeScriptCompilerError') -}) diff --git a/python/tests/async/test_async_default_kernels.py b/python/tests/async/test_async_default_kernels.py index 83f92746..88df4a94 100644 --- a/python/tests/async/test_async_default_kernels.py +++ b/python/tests/async/test_async_default_kernels.py @@ -13,11 +13,3 @@ async def test_ts_kernel(async_sandbox: AsyncSandbox): "const message: string = 'Hello, World!'; console.log(message);", language="ts" ) assert execution.logs.stdout == ["Hello, World!\n"] - - -async def test_ts_kernel_errors(async_sandbox: AsyncSandbox): - execution = await async_sandbox.run_code( - "import x from 'module';", language="ts" - ) - assert execution.error is not None - assert execution.error.name == "TypeScriptCompilerError" diff --git a/python/tests/sync/test_default_kernels.py b/python/tests/sync/test_default_kernels.py index 0695defd..71abadfc 100644 --- a/python/tests/sync/test_default_kernels.py +++ b/python/tests/sync/test_default_kernels.py @@ -25,8 +25,3 @@ def test_ts_kernel(sandbox: Sandbox): execution = sandbox.run_code("const message: string = 'Hello, World!'; console.log(message)", language="ts") assert execution.logs.stdout == ["Hello, World!\n"] - -def test_ts_kernel_errors(sandbox: Sandbox): - execution = sandbox.run_code("import x from 'module';", language="ts") - assert execution.error is not None - assert execution.error.name == "TypeScriptCompilerError" diff --git a/template/.ts.swcrc b/template/.ts.swcrc deleted file mode 100644 index cf7cb8d3..00000000 --- a/template/.ts.swcrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "https://swc.rs/schema.json", - "jsc": { - "parser": { - "syntax": "typescript" - } - }, - "module": { - "type": "commonjs" - }, - "env": { - "targets": "node 20" - }, - "isModule": false -} diff --git a/template/Dockerfile b/template/Dockerfile index c48f7df9..a4bb24d0 100644 --- a/template/Dockerfile +++ b/template/Dockerfile @@ -28,13 +28,9 @@ RUN R -e "install.packages('IRkernel', repos='https://cloud.r-project.org')" RUN R -e "IRkernel::installspec(user = FALSE, name = 'r', displayname = 'R')" # Javascript Kernel -RUN npm install -g --unsafe-perm ijavascript +RUN npm install -g --unsafe-perm git+https://github.com/e2b-dev/ijavascript.git RUN ijsinstall --install=global -## TypeScript compiler -RUN npm install -g @swc/cli @swc/core -COPY .ts.swcrc $SERVER_PATH/.ts.swcrc - # Deno Kernel COPY --from=denoland/deno:bin-2.0.4 /deno /usr/bin/deno RUN chmod +x /usr/bin/deno diff --git a/template/server/messaging.py b/template/server/messaging.py index d2894d92..9fe4e081 100644 --- a/template/server/messaging.py +++ b/template/server/messaging.py @@ -199,32 +199,6 @@ async def execute( + code ) - if self.language == "typescript": - logger.info("Compiling TypeScript: %s", code) - - # call SWC to compile the typescript code - try: - compile_result = subprocess.run("swc --config-file .ts.swcrc --filename index.ts".split(), input=code.encode(), capture_output=True) - - if compile_result.returncode != 0: - logger.error("Error during TypeScript compilation: %s", compile_result.stderr.decode()) - yield Error( - name="TypeScriptCompilerError", - value=compile_result.stderr.decode(), - traceback="", - ) - return - - code = compile_result.stdout.decode() - except Exception as e: - logger.error("Error starting SWC process: %s", e) - yield Error( - name="TypeScriptCompilerError", - value=str(e), - traceback="", - ) - return - logger.info(code) request = self._get_execute_request(message_id, code, False) diff --git a/template/test.Dockerfile b/template/test.Dockerfile index 9a6c2f21..14eb0005 100644 --- a/template/test.Dockerfile +++ b/template/test.Dockerfile @@ -23,13 +23,9 @@ COPY ./template/requirements.txt requirements.txt RUN pip install --no-cache-dir -r requirements.txt && ipython kernel install --name "python3" --user # Javascript Kernel -RUN npm install -g --unsafe-perm ijavascript +RUN npm install -g --unsafe-perm git+https://github.com/e2b-dev/ijavascript.git RUN ijsinstall --install=global -## TypeScript compiler -RUN npm install -g @swc/cli @swc/core -COPY ./template/.ts.swcrc $SERVER_PATH/.ts.swcrc - # Deno Kernel COPY --from=denoland/deno:bin-2.0.4 /deno /usr/bin/deno RUN chmod +x /usr/bin/deno From 585543f98d19d0273cc2cd38f1a51087bf397579 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 28 May 2025 13:08:52 +0000 Subject: [PATCH 10/16] [skip ci] Release new versions --- .changeset/breezy-bananas-lay.md | 5 ----- template/package.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .changeset/breezy-bananas-lay.md diff --git a/.changeset/breezy-bananas-lay.md b/.changeset/breezy-bananas-lay.md deleted file mode 100644 index c7d185b0..00000000 --- a/.changeset/breezy-bananas-lay.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@e2b/code-interpreter-template': patch ---- - -updated ijavascript kernel in the template diff --git a/template/package.json b/template/package.json index 222d0d21..fd7d6236 100644 --- a/template/package.json +++ b/template/package.json @@ -1,5 +1,5 @@ { "name": "@e2b/code-interpreter-template", "private": true, - "version": "0.0.10" + "version": "0.0.11" } From 85cac9199b9ed5e4b59a4eb9afb7117ccb142640 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Wed, 28 May 2025 19:34:18 +0200 Subject: [PATCH 11/16] added tests for new js kernel (#113) --- js/tests/defaultKernels.test.ts | 28 +++++++++++++++++++ .../tests/async/test_async_default_kernels.py | 14 ++++++++++ python/tests/sync/test_default_kernels.py | 15 ++++++++++ 3 files changed, 57 insertions(+) diff --git a/js/tests/defaultKernels.test.ts b/js/tests/defaultKernels.test.ts index 41bc245b..f5fce337 100644 --- a/js/tests/defaultKernels.test.ts +++ b/js/tests/defaultKernels.test.ts @@ -9,6 +9,34 @@ sandboxTest('test js kernel', async ({ sandbox }) => { expect(output.logs.stdout).toEqual(['Hello World!\n']) }) +sandboxTest('test esm imports', async ({ sandbox }) => { + const output = await sandbox.runCode( + ` + import { readFileSync } from 'fs' + console.log(typeof readFileSync) + `, + { + language: 'js', + } + ) + expect(output.logs.stdout).toEqual(['function\n']) +}) + +sandboxTest( + 'test top-level await and promise resolution', + async ({ sandbox }) => { + const output = await sandbox.runCode( + ` + await Promise.resolve('Hello World!') + `, + { + language: 'js', + } + ) + expect(output.text).toEqual('Hello World!') + } +) + sandboxTest('test ts kernel', async ({ sandbox }) => { const output = await sandbox.runCode( 'const message: string = "Hello World!"; console.log(message)', diff --git a/python/tests/async/test_async_default_kernels.py b/python/tests/async/test_async_default_kernels.py index 88df4a94..23b01b35 100644 --- a/python/tests/async/test_async_default_kernels.py +++ b/python/tests/async/test_async_default_kernels.py @@ -7,6 +7,20 @@ async def test_js_kernel(async_sandbox: AsyncSandbox): ) assert execution.logs.stdout == ["Hello, World!\n"] +async def test_js_esm_imports(async_sandbox: AsyncSandbox): + execution = await async_sandbox.run_code(""" + import { readFileSync } from 'fs' + console.log(typeof readFileSync) + """, language="js") + assert execution.logs.stdout == ["function\n"] + + +async def test_js_top_level_await(async_sandbox: AsyncSandbox): + execution = await async_sandbox.run_code(""" + await Promise.resolve('Hello World!') + """, language="js") + assert execution.text == "Hello World!" + async def test_ts_kernel(async_sandbox: AsyncSandbox): execution = await async_sandbox.run_code( diff --git a/python/tests/sync/test_default_kernels.py b/python/tests/sync/test_default_kernels.py index 71abadfc..998a39e8 100644 --- a/python/tests/sync/test_default_kernels.py +++ b/python/tests/sync/test_default_kernels.py @@ -20,6 +20,21 @@ def test_java_kernel(sandbox: Sandbox): assert execution.logs.stdout[0] == "Hello, World!" +def test_js_esm_imports(sandbox: Sandbox): + execution = sandbox.run_code(""" + import { readFileSync } from 'fs' + console.log(typeof readFileSync) + """, language="js") + assert execution.logs.stdout == ["function\n"] + + +def test_js_top_level_await(sandbox: Sandbox): + execution = sandbox.run_code(""" + await Promise.resolve('Hello World!') + """, language="js") + assert execution.text == "Hello World!" + + @pytest.mark.skip_debug() def test_ts_kernel(sandbox: Sandbox): execution = sandbox.run_code("const message: string = 'Hello, World!'; console.log(message)", language="ts") From 2b7833b6b9ab413ecacd6926c1b2833b2ca278c2 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:24:59 +0200 Subject: [PATCH 12/16] added MIT license to code-interpreter SDKs and charts library (#117) --- .changeset/shaggy-cups-compare.md | 7 +++++++ chart_data_extractor/LICENSE | 9 +++++++++ chart_data_extractor/pyproject.toml | 2 +- js/LICENSE | 9 +++++++++ python/LICENSE | 9 +++++++++ python/pyproject.toml | 2 +- 6 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 .changeset/shaggy-cups-compare.md create mode 100644 chart_data_extractor/LICENSE create mode 100644 js/LICENSE create mode 100644 python/LICENSE diff --git a/.changeset/shaggy-cups-compare.md b/.changeset/shaggy-cups-compare.md new file mode 100644 index 00000000..2242a953 --- /dev/null +++ b/.changeset/shaggy-cups-compare.md @@ -0,0 +1,7 @@ +--- +'@e2b/data-extractor': patch +'@e2b/code-interpreter-python': patch +'@e2b/code-interpreter': patch +--- + +added MIT License source diff --git a/chart_data_extractor/LICENSE b/chart_data_extractor/LICENSE new file mode 100644 index 00000000..4aa6529d --- /dev/null +++ b/chart_data_extractor/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 FOUNDRYLABS, INC. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/chart_data_extractor/pyproject.toml b/chart_data_extractor/pyproject.toml index 6ca00367..4694b151 100644 --- a/chart_data_extractor/pyproject.toml +++ b/chart_data_extractor/pyproject.toml @@ -3,7 +3,7 @@ name = "e2b-charts" version = "0.0.3" description = "Package for extracting data for E2B Code Interpreter" authors = ["e2b "] -license = "Apache-2.0" +license = "MIT" readme = "README.md" homepage = "https://e2b.dev/" repository = "https://github.com/e2b-dev/e2b-code-interpreter/tree/python" diff --git a/js/LICENSE b/js/LICENSE new file mode 100644 index 00000000..4aa6529d --- /dev/null +++ b/js/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 FOUNDRYLABS, INC. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/python/LICENSE b/python/LICENSE new file mode 100644 index 00000000..4aa6529d --- /dev/null +++ b/python/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 FOUNDRYLABS, INC. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/python/pyproject.toml b/python/pyproject.toml index d1d859cf..b8b857a2 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -3,7 +3,7 @@ name = "e2b-code-interpreter" version = "1.5.0" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] -license = "Apache-2.0" +license = "MIT" readme = "README.md" homepage = "https://e2b.dev/" repository = "https://github.com/e2b-dev/code-interpreter/tree/main/python" From c87f122de41b80e1458ffb0e50ea18df4583284a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 5 Jun 2025 14:38:09 +0000 Subject: [PATCH 13/16] [skip ci] Release new versions --- .changeset/shaggy-cups-compare.md | 7 - chart_data_extractor/package.json | 2 +- chart_data_extractor/pyproject.toml | 2 +- js/package.json | 2 +- python/package.json | 2 +- python/pyproject.toml | 2 +- .../v1.5.1/charts/page.mdx | 240 ++++++ .../v1.5.1/consts/page.mdx | 13 + .../v1.5.1/index/page.mdx | 103 +++ .../v1.5.1/messaging/page.mdx | 326 ++++++++ .../v1.5.1/sandbox/page.mdx | 312 ++++++++ .../v1.5.1/sandbox/page.mdx | 722 ++++++++++++++++++ 12 files changed, 1721 insertions(+), 12 deletions(-) delete mode 100644 .changeset/shaggy-cups-compare.md create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.1/charts/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.1/consts/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.1/index/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.1/messaging/page.mdx create mode 100644 sdk-reference/code-interpreter-js-sdk/v1.5.1/sandbox/page.mdx create mode 100644 sdk-reference/code-interpreter-python-sdk/v1.5.1/sandbox/page.mdx diff --git a/.changeset/shaggy-cups-compare.md b/.changeset/shaggy-cups-compare.md deleted file mode 100644 index 2242a953..00000000 --- a/.changeset/shaggy-cups-compare.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@e2b/data-extractor': patch -'@e2b/code-interpreter-python': patch -'@e2b/code-interpreter': patch ---- - -added MIT License source diff --git a/chart_data_extractor/package.json b/chart_data_extractor/package.json index 8135e77c..41cb32b8 100644 --- a/chart_data_extractor/package.json +++ b/chart_data_extractor/package.json @@ -1,7 +1,7 @@ { "name": "@e2b/data-extractor", "private": true, - "version": "0.0.3", + "version": "0.0.4", "scripts": { "test": "poetry run pytest -n 4 --verbose -x", "example": "poetry run python3 example.py", diff --git a/chart_data_extractor/pyproject.toml b/chart_data_extractor/pyproject.toml index 4694b151..745d7588 100644 --- a/chart_data_extractor/pyproject.toml +++ b/chart_data_extractor/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-charts" -version = "0.0.3" +version = "0.0.4" description = "Package for extracting data for E2B Code Interpreter" authors = ["e2b "] license = "MIT" diff --git a/js/package.json b/js/package.json index 27c76fd4..938d5c2e 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "1.5.0", + "version": "1.5.1", "packageManager": "pnpm@8.7.6", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", diff --git a/python/package.json b/python/package.json index cee595b9..319c24d6 100644 --- a/python/package.json +++ b/python/package.json @@ -1,7 +1,7 @@ { "name": "@e2b/code-interpreter-python", "private": true, - "version": "1.5.0", + "version": "1.5.1", "packageManager": "pnpm@8.7.6", "scripts": { "test": "poetry run pytest -n 4 --verbose -x", diff --git a/python/pyproject.toml b/python/pyproject.toml index b8b857a2..4208cf65 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "1.5.0" +version = "1.5.1" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "MIT" diff --git a/sdk-reference/code-interpreter-js-sdk/v1.5.1/charts/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.1/charts/page.mdx new file mode 100644 index 00000000..f3176d3b --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.1/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/sdk-reference/code-interpreter-js-sdk/v1.5.1/consts/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.1/consts/page.mdx new file mode 100644 index 00000000..d1ee2e76 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.1/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/sdk-reference/code-interpreter-js-sdk/v1.5.1/index/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.1/index/page.mdx new file mode 100644 index 00000000..dc55fcc7 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.1/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/sdk-reference/code-interpreter-js-sdk/v1.5.1/messaging/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.1/messaging/page.mdx new file mode 100644 index 00000000..4b3c4ed9 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.1/messaging/page.mdx @@ -0,0 +1,326 @@ +### 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 + +```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 +``` + +#### 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 +``` + +#### 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/sdk-reference/code-interpreter-js-sdk/v1.5.1/sandbox/page.mdx b/sdk-reference/code-interpreter-js-sdk/v1.5.1/sandbox/page.mdx new file mode 100644 index 00000000..96eafec5 --- /dev/null +++ b/sdk-reference/code-interpreter-js-sdk/v1.5.1/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 +``` + +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 +``` + +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 +``` + +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 +``` + +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; +``` + +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/sdk-reference/code-interpreter-python-sdk/v1.5.1/sandbox/page.mdx b/sdk-reference/code-interpreter-python-sdk/v1.5.1/sandbox/page.mdx new file mode 100644 index 00000000..6bee4003 --- /dev/null +++ b/sdk-reference/code-interpreter-python-sdk/v1.5.1/sandbox/page.mdx @@ -0,0 +1,722 @@ + + + + + +## OutputMessage + +```python +@dataclass +class OutputMessage() +``` + +Represents an output message from the sandbox code execution. + + +### line + +The output line. + + +### timestamp + +Unix epoch in nanoseconds + + +### error + +Whether the output is an error. + + +## ExecutionError + +```python +@dataclass +class 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. + + +### name + +Name of the error. + + +### value + +Value of the error. + + +### traceback + +The raw traceback of the error. + + +### to\_json + +```python +def to_json() -> str +``` + +Returns the JSON representation of the Error object. + + +## MIMEType + +```python +class MIMEType(str) +``` + +Represents a MIME type. + + +## Result + +```python +@dataclass +class 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. + + +### is\_main\_result + +Whether this data is the result of the cell. Data can be produced by display calls of which can be multiple in a cell. + + +### extra + +Extra data that can be included. Not part of the standard types. + + +### formats + +```python +def formats() -> Iterable[str] +``` + +Returns all available formats of the result. + +**Returns**: + +All available formats of the result in MIME types. + + +### \_\_str\_\_ + +```python +def __str__() -> Optional[str] +``` + +Returns the text representation of the data. + +**Returns**: + +The text representation of the data. + + +### \_repr\_html\_ + +```python +def _repr_html_() -> Optional[str] +``` + +Returns the HTML representation of the data. + +**Returns**: + +The HTML representation of the data. + + +### \_repr\_markdown\_ + +```python +def _repr_markdown_() -> Optional[str] +``` + +Returns the Markdown representation of the data. + +**Returns**: + +The Markdown representation of the data. + + +### \_repr\_svg\_ + +```python +def _repr_svg_() -> Optional[str] +``` + +Returns the SVG representation of the data. + +**Returns**: + +The SVG representation of the data. + + +### \_repr\_png\_ + +```python +def _repr_png_() -> Optional[str] +``` + +Returns the base64 representation of the PNG data. + +**Returns**: + +The base64 representation of the PNG data. + + +### \_repr\_jpeg\_ + +```python +def _repr_jpeg_() -> Optional[str] +``` + +Returns the base64 representation of the JPEG data. + +**Returns**: + +The base64 representation of the JPEG data. + + +### \_repr\_pdf\_ + +```python +def _repr_pdf_() -> Optional[str] +``` + +Returns the PDF representation of the data. + +**Returns**: + +The PDF representation of the data. + + +### \_repr\_latex\_ + +```python +def _repr_latex_() -> Optional[str] +``` + +Returns the LaTeX representation of the data. + +**Returns**: + +The LaTeX representation of the data. + + +### \_repr\_json\_ + +```python +def _repr_json_() -> Optional[dict] +``` + +Returns the JSON representation of the data. + +**Returns**: + +The JSON representation of the data. + + +### \_repr\_javascript\_ + +```python +def _repr_javascript_() -> Optional[str] +``` + +Returns the JavaScript representation of the data. + +**Returns**: + +The JavaScript representation of the data. + + +## Logs + +```python +@dataclass(repr=False) +class Logs() +``` + +Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc. + + +### stdout + +List of strings printed to stdout by prints, subprocesses, etc. + + +### stderr + +List of strings printed to stderr by prints, subprocesses, etc. + + +### to\_json + +```python +def to_json() -> str +``` + +Returns the JSON representation of the Logs object. + + +### serialize\_results + +```python +def serialize_results(results: List[Result]) -> List[Dict[str, str]] +``` + +Serializes the results to JSON. + + +## Execution + +```python +@dataclass(repr=False) +class Execution() +``` + +Represents the result of a cell execution. + + +### results + +List of the result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots). + + +### logs + +Logs printed to stdout and stderr during execution. + + +### error + +Error object if an error occurred, None otherwise. + + +### execution\_count + +Execution count of the cell. + + +### text + +```python +@property +def text() -> Optional[str] +``` + +Returns the text representation of the result. + +**Returns**: + +The text representation of the result. + + +### to\_json + +```python +def to_json() -> str +``` + +Returns the JSON representation of the Execution object. + + +## Context + +```python +@dataclass +class Context() +``` + +Represents a context for code execution. + + +### id + +The ID of the context. + + +### language + +The language of the context. + + +### cwd + +The working directory of the context. + + + + + + +## AsyncSandbox + +```python +class AsyncSandbox(BaseAsyncSandbox) +``` + +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 `AsyncSandbox.create()` to create a new sandbox. + +**Example**: + +```python +from e2b_code_interpreter import AsyncSandbox +sandbox = await AsyncSandbox.create() +``` + + +### run\_code + +```python +@overload +async def run_code(code: str, + language: Union[Literal["python"], None] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +async def run_code(code: str, + language: Optional[str] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +async def run_code(code: str, + context: Optional[Context] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> 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. + +**Arguments**: + +- `code`: Code to execute +- `context`: Concrete context to run the code in. If not specified, the default context for the language is used. It's mutually exclusive with the language. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### create\_code\_context + +```python +async def create_code_context( + cwd: Optional[str] = None, + language: Optional[str] = None, + request_timeout: Optional[float] = None) -> Context +``` + +Creates a new context to run code in. + +**Arguments**: + +- `cwd`: Set the current working directory for the context, defaults to `/home/user` +- `language`: Language of the context. If not specified, defaults to Python +- `request_timeout`: Timeout for the request in **milliseconds** + +**Returns**: + +Context object + + + + +## ChartType + +```python +class ChartType(str, enum.Enum) +``` + +Chart types + + +## ScaleType + +```python +class ScaleType(str, enum.Enum) +``` + +Ax scale types + + +## Chart + +```python +class Chart() +``` + +Extracted data from a chart. It's useful for building an interactive charts or custom visualizations. + + + + + + +## Sandbox + +```python +class Sandbox(BaseSandbox) +``` + +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_code_interpreter import Sandbox + +sandbox = Sandbox() +``` + + +### run\_code + +```python +@overload +def run_code(code: str, + language: Union[Literal["python"], None] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +def run_code(code: str, + language: Optional[str] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> Execution +``` + +Runs 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. + +**Arguments**: + +- `code`: Code to execute +- `language`: Language to use for code execution. If not defined, the default Python context is used. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### run\_code + +```python +@overload +def run_code(code: str, + context: Optional[Context] = None, + on_stdout: Optional[OutputHandler[OutputMessage]] = None, + on_stderr: Optional[OutputHandler[OutputMessage]] = None, + on_result: Optional[OutputHandler[Result]] = None, + on_error: Optional[OutputHandler[ExecutionError]] = None, + envs: Optional[Dict[str, str]] = None, + timeout: Optional[float] = None, + request_timeout: Optional[float] = None) -> 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. + +**Arguments**: + +- `code`: Code to execute +- `context`: Concrete context to run the code in. If not specified, the default context for the language is used. It's mutually exclusive with the language. +- `on_stdout`: Callback for stdout messages +- `on_stderr`: Callback for stderr messages +- `on_result`: Callback for the `Result` object +- `on_error`: Callback for the `ExecutionError` object +- `envs`: Custom environment variables +- `timeout`: Timeout for the code execution in **seconds** +- `request_timeout`: Timeout for the request in **seconds** + +**Returns**: + +`Execution` result object + + +### create\_code\_context + +```python +def create_code_context(cwd: Optional[str] = None, + language: Optional[str] = None, + request_timeout: Optional[float] = None) -> Context +``` + +Creates a new context to run code in. + +**Arguments**: + +- `cwd`: Set the current working directory for the context, defaults to `/home/user` +- `language`: Language of the context. If not specified, defaults to Python +- `request_timeout`: Timeout for the request in **milliseconds** + +**Returns**: + +Context object + From cef0e440ae901148958366a48e49ca925316cae6 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Fri, 6 Jun 2025 09:31:52 +0200 Subject: [PATCH 14/16] Added CI/CD for code interpreter template (#116) --- .github/workflows/build_test_template.yml | 55 ++++++++++++++++++++ .github/workflows/charts_tests.yml | 2 +- .github/workflows/cleanup_build_template.yml | 33 ++++++++++++ .github/workflows/js_tests.yml | 17 +++++- .github/workflows/pull_request.yml | 23 ++++++++ .github/workflows/python_tests.yml | 11 +++- .github/workflows/release.yml | 17 +++--- js/tests/setup.ts | 6 ++- python/tests/conftest.py | 17 +++--- 9 files changed, 159 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/build_test_template.yml create mode 100644 .github/workflows/cleanup_build_template.yml diff --git a/.github/workflows/build_test_template.yml b/.github/workflows/build_test_template.yml new file mode 100644 index 00000000..e8d6edb2 --- /dev/null +++ b/.github/workflows/build_test_template.yml @@ -0,0 +1,55 @@ +name: Build Template + +on: + workflow_call: + secrets: + E2B_TESTS_ACCESS_TOKEN: + required: true + inputs: + E2B_DOMAIN: + required: false + type: string + outputs: + template_id: + description: "The ID of the built template" + value: ${{ jobs.build.outputs.template_id }} + +permissions: + contents: read + +jobs: + build: + name: Build E2B Template + runs-on: ubuntu-latest + outputs: + template_id: ${{ steps.build-template.outputs.template_id }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set package version + working-directory: ./template + run: | + VERSION=$(cat ../chart_data_extractor/pyproject.toml | grep version | cut -d '"' -f 2) + echo "Version: $VERSION" + sed -i "s/e2b_charts/e2b_charts==${VERSION}/g" requirements.txt + + - name: Install E2B CLI + run: npm install -g @e2b/cli + + - name: Build E2B template + id: build-template + run: | + rm -f e2b.toml + e2b template build --memory-mb 1024 -c "/root/.jupyter/start-up.sh" -d "Dockerfile" + TEMPLATE_ID=$(grep "template_id" e2b.toml | cut -d '"' -f 2) + echo "Captured Template ID: $TEMPLATE_ID" + echo "template_id=$TEMPLATE_ID" >> $GITHUB_OUTPUT + working-directory: ./template + env: + E2B_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }} + + - name: Output template ID + run: | + echo "Template ID from step output: ${{ steps.build-template.outputs.template_id }}" diff --git a/.github/workflows/charts_tests.yml b/.github/workflows/charts_tests.yml index 985e7d99..6cbc59e1 100644 --- a/.github/workflows/charts_tests.yml +++ b/.github/workflows/charts_tests.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 diff --git a/.github/workflows/cleanup_build_template.yml b/.github/workflows/cleanup_build_template.yml new file mode 100644 index 00000000..9878474c --- /dev/null +++ b/.github/workflows/cleanup_build_template.yml @@ -0,0 +1,33 @@ +name: Cleanup Build Template + +on: + workflow_call: + secrets: + E2B_TESTS_ACCESS_TOKEN: + required: true + inputs: + E2B_DOMAIN: + required: false + type: string + E2B_TESTS_TEMPLATE: + required: true + type: string + +permissions: + contents: read + +jobs: + cleanup: + name: Cleanup Build Template + runs-on: ubuntu-latest + steps: + - name: Install E2B CLI + run: npm install -g @e2b/cli + + - name: Cleanup E2B template + id: cleanup-template + run: | + e2b template delete -y "${{ inputs.E2B_TESTS_TEMPLATE }}" + env: + E2B_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }} diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml index f791115a..144603f6 100644 --- a/.github/workflows/js_tests.yml +++ b/.github/workflows/js_tests.yml @@ -5,6 +5,13 @@ on: secrets: E2B_API_KEY: required: true + inputs: + E2B_DOMAIN: + required: false + type: string + E2B_TESTS_TEMPLATE: + required: false + type: string permissions: contents: read @@ -18,7 +25,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -49,16 +56,20 @@ jobs: run: pnpm test env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} - name: Install Bun uses: oven-sh/setup-bun@v2 with: - version: 1.1.x + bun-version: 1.2.15 - name: Run Bun tests run: pnpm test:bun env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} - name: Install Deno uses: denoland/setup-deno@v1 @@ -69,3 +80,5 @@ jobs: run: pnpm test:deno env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 78b42016..29aa1e15 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -14,13 +14,36 @@ on: - main jobs: + build-template: + uses: ./.github/workflows/build_test_template.yml + secrets: + E2B_TESTS_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} js-sdk: uses: ./.github/workflows/js_tests.yml + needs: build-template secrets: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ needs.build-template.outputs.template_id }} python-sdk: uses: ./.github/workflows/python_tests.yml + needs: build-template secrets: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ needs.build-template.outputs.template_id }} + cleanup-build-template: + uses: ./.github/workflows/cleanup_build_template.yml + needs: [build-template, js-sdk, python-sdk] + if: always() && !contains(needs.build-template.result, 'failure') && !contains(needs.build-template.result, 'cancelled') + secrets: + E2B_TESTS_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ needs.build-template.outputs.template_id }} charts-tests: uses: ./.github/workflows/charts_tests.yml diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 5bb46fea..22c85536 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -5,6 +5,13 @@ on: secrets: E2B_API_KEY: required: true + inputs: + E2B_DOMAIN: + required: false + type: string + E2B_TESTS_TEMPLATE: + required: false + type: string permissions: contents: read @@ -18,7 +25,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 @@ -43,3 +50,5 @@ jobs: run: poetry run pytest --verbose -x env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 523f8531..8ee6313b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: release: ${{ steps.version.outputs.release }} steps: - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -60,7 +60,7 @@ jobs: template: ${{ steps.template.outputs.release }} steps: - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -117,7 +117,7 @@ jobs: version: ${{ steps.output_version.outputs.version }} steps: - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -177,9 +177,7 @@ jobs: (needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true') steps: - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -220,9 +218,7 @@ jobs: (needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true') steps: - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 + uses: actions/checkout@v4 - name: Install E2B CLI run: npm install -g @e2b/cli @@ -268,9 +264,8 @@ jobs: private-key: ${{ secrets.VERSION_BUMPER_SECRET }} - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - fetch-depth: 0 token: ${{ steps.app-token.outputs.token }} diff --git a/js/tests/setup.ts b/js/tests/setup.ts index b4466365..52cd7c65 100644 --- a/js/tests/setup.ts +++ b/js/tests/setup.ts @@ -3,6 +3,8 @@ import { test as base } from 'vitest' const timeoutMs = 60_000 +const template = process.env.E2B_TESTS_TEMPLATE || 'code-interpreter-v1' + interface SandboxFixture { sandbox: Sandbox } @@ -10,7 +12,9 @@ interface SandboxFixture { export const sandboxTest = base.extend({ sandbox: [ async ({}, use) => { - const sandbox = await Sandbox.create({ timeoutMs }) + const sandbox = await Sandbox.create(template, { + timeoutMs, + }) try { await use(sandbox) } finally { diff --git a/python/tests/conftest.py b/python/tests/conftest.py index efb6c1d7..796eab91 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -11,8 +11,13 @@ @pytest.fixture() -def sandbox(debug): - sandbox = Sandbox(timeout=timeout) +def template(): + return os.getenv("E2B_TESTS_TEMPLATE", "code-interpreter-v1") + + +@pytest.fixture() +def sandbox(template, debug): + sandbox = Sandbox(template, timeout=timeout) try: yield sandbox @@ -27,14 +32,14 @@ def sandbox(debug): @pytest_asyncio.fixture -async def async_sandbox(debug): - sandbox = await AsyncSandbox.create(timeout=timeout) +async def async_sandbox(template, debug): + async_sandbox = await AsyncSandbox.create(template, timeout=timeout) try: - yield sandbox + yield async_sandbox finally: try: - await sandbox.kill() + await async_sandbox.kill() except: if not debug: warning( From 22c5d4d2b367e2f96f1d1097b430ebdd03f34bb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:22:26 +0000 Subject: [PATCH 15/16] Bump requests in /template/server in the pip group across 1 directory (#118) Bumps the pip group with 1 update in the /template/server directory: [requests](https://github.com/psf/requests). Updates `requests` from 2.32.2 to 2.32.4 - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.32.2...v2.32.4) --- updated-dependencies: - dependency-name: requests dependency-version: 2.32.4 dependency-type: direct:production dependency-group: pip ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- template/server/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/server/requirements.txt b/template/server/requirements.txt index 38aa52e3..52385cb6 100644 --- a/template/server/requirements.txt +++ b/template/server/requirements.txt @@ -2,5 +2,5 @@ fastapi==0.111.0 httpx==0.27.0 websockets==12.0 uvicorn[standard]==0.30.1 -requests==2.32.2 +requests==2.32.4 pydantic==2.9.1 From bf43b6d60ef29f75a673bca820116ad70edcf709 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Jun 2025 13:14:21 -0700 Subject: [PATCH 16/16] Bump the pip group across 2 directories with 1 update (#119) Bumps the pip group with 1 update in the /python directory: [requests](https://github.com/psf/requests). Bumps the pip group with 1 update in the /template directory: [requests](https://github.com/psf/requests). Updates `requests` from 2.32.3 to 2.32.4 - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.32.3...v2.32.4) Updates `requests` from 2.32.3 to 2.32.4 - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.32.3...v2.32.4) --- updated-dependencies: - dependency-name: requests dependency-version: 2.32.4 dependency-type: indirect dependency-group: pip - dependency-name: requests dependency-version: 2.32.4 dependency-type: direct:production dependency-group: pip ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- python/poetry.lock | 9 +++++---- template/requirements.txt | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/python/poetry.lock b/python/poetry.lock index 70a17901..0f55d824 100644 --- a/python/poetry.lock +++ b/python/poetry.lock @@ -916,19 +916,19 @@ files = [ [[package]] name = "requests" -version = "2.32.3" +version = "2.32.4" description = "Python HTTP for Humans." optional = false python-versions = ">=3.8" groups = ["dev"] files = [ - {file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"}, - {file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"}, + {file = "requests-2.32.4-py3-none-any.whl", hash = "sha256:27babd3cda2a6d50b30443204ee89830707d396671944c998b5975b031ac2b2c"}, + {file = "requests-2.32.4.tar.gz", hash = "sha256:27d0316682c8a29834d3264820024b62a36942083d52caf2f14c0591336d3422"}, ] [package.dependencies] certifi = ">=2017.4.17" -charset-normalizer = ">=2,<4" +charset_normalizer = ">=2,<4" idna = ">=2.5,<4" urllib3 = ">=1.21.1,<3" @@ -943,6 +943,7 @@ description = "Easily download, build, install, upgrade, and uninstall Python pa optional = false python-versions = ">=3.9" groups = ["dev"] +markers = "python_version < \"3.10\"" files = [ {file = "setuptools-78.1.1-py3-none-any.whl", hash = "sha256:c3a9c4211ff4c309edb8b8c4f1cbfa7ae324c4ba9f91ff254e3d305b9fd54561"}, {file = "setuptools-78.1.1.tar.gz", hash = "sha256:fcc17fd9cd898242f6b4adfaca46137a9edef687f43e6f78469692a5e70d851d"}, diff --git a/template/requirements.txt b/template/requirements.txt index 3adbfdb5..b44f7b9f 100644 --- a/template/requirements.txt +++ b/template/requirements.txt @@ -28,7 +28,7 @@ plotly==6.0.1 pytest==8.3.5 python-docx==1.1.2 pytz==2025.2 -requests==2.32.3 +requests==2.32.4 scikit-image==0.25.2 scikit-learn==1.6.1 scipy==1.13.1 # bump blocked by gensim