> ## Documentation Index
> Fetch the complete documentation index at: https://e2b-mintlify-6744e86b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Messaging

### Execution

Represents the result of a cell execution.

#### Constructors

```ts theme={null}
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                                                                                              |
| ------------------------------------------- | -------- | ---------------- | ------------- | -------------------------------------------------------------------------------------------------------- |
| <a id="error" /> `error?`                   | `public` | `ExecutionError` | `undefined`   | An Error object if an error occurred, null otherwise.                                                    |
| <a id="executioncount" /> `executionCount?` | `public` | `number`         | `undefined`   | Execution count of the cell.                                                                             |
| <a id="logs" /> `logs`                      | `public` | `Logs`           | `undefined`   | Logs printed to stdout and stderr during execution.                                                      |
| <a id="results" /> `results`                | `public` | `Result`\[]      | `[]`          | List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots). |

#### Accessors

### text

###### Get Signature

```ts theme={null}
get text(): undefined | string
```

Returns the text representation of the main result of the cell.

###### Returns

`undefined` | `string`

#### Methods

### toJSON()

```ts theme={null}
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 theme={null}
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                     |
| -------------------------------- | -------- | -------- | ------------------------------- |
| <a id="name" /> `name`           | `public` | `string` | Name of the error.              |
| <a id="traceback" /> `traceback` | `public` | `string` | The raw traceback of the error. |
| <a id="value" /> `value`         | `public` | `string` | Value of the error.             |

***

### OutputMessage

Represents an output message from the sandbox code execution.

#### Constructors

```ts theme={null}
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                     |
| -------------------------------- | ---------- | --------- | ------------------------------- |
| <a id="error-1" /> `error`       | `readonly` | `boolean` | Whether the output is an error. |
| <a id="line" /> `line`           | `readonly` | `string`  | The output line.                |
| <a id="timestamp" /> `timestamp` | `readonly` | `number`  | Unix epoch in nanoseconds.      |

#### Methods

### toString()

```ts theme={null}
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](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 theme={null}
new Result(rawData: RawData, isMainResult: boolean): Result
```

###### Parameters

| Parameter      | Type      |
| -------------- | --------- |
| `rawData`      | `RawData` |
| `isMainResult` | `boolean` |

###### Returns

`Result`

#### Properties

| Property                               | Modifier   | Type                           | Description                                                      |
| -------------------------------------- | ---------- | ------------------------------ | ---------------------------------------------------------------- |
| <a id="chart" /> `chart?`              | `readonly` | `ChartTypes`                   | Contains the chart data.                                         |
| <a id="data" /> `data?`                | `readonly` | `Record`\<`string`, `unknown`> | Contains the data from DataFrame.                                |
| <a id="extra" /> `extra?`              | `readonly` | `any`                          | Extra data that can be included. Not part of the standard types. |
| <a id="html" /> `html?`                | `readonly` | `string`                       | HTML representation of the data.                                 |
| <a id="ismainresult" /> `isMainResult` | `readonly` | `boolean`                      | -                                                                |
| <a id="javascript" /> `javascript?`    | `readonly` | `string`                       | JavaScript representation of the data.                           |
| <a id="jpeg" /> `jpeg?`                | `readonly` | `string`                       | JPEG representation of the data.                                 |
| <a id="json" /> `json?`                | `readonly` | `string`                       | JSON representation of the data.                                 |
| <a id="latex" /> `latex?`              | `readonly` | `string`                       | LaTeX representation of the data.                                |
| <a id="markdown" /> `markdown?`        | `readonly` | `string`                       | Markdown representation of the data.                             |
| <a id="pdf" /> `pdf?`                  | `readonly` | `string`                       | PDF representation of the data.                                  |
| <a id="png" /> `png?`                  | `readonly` | `string`                       | PNG representation of the data.                                  |
| <a id="raw" /> `raw`                   | `readonly` | `RawData`                      | -                                                                |
| <a id="svg" /> `svg?`                  | `readonly` | `string`                       | SVG representation of the data.                                  |
| <a id="text-1" /> `text?`              | `readonly` | `string`                       | Text representation of the result.                               |

#### Methods

### formats()

```ts theme={null}
formats(): string[]
```

Returns all the formats available for the result.

###### Returns

`string`\[]

Array of strings representing the formats available for the result.

### toJSON()

```ts theme={null}
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 theme={null}
type Logs = object;
```

Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.

#### Type declaration

| Name                       | Type        | Description                                                     |
| -------------------------- | ----------- | --------------------------------------------------------------- |
| <a id="stderr" /> `stderr` | `string`\[] | List of strings printed to stderr by prints, subprocesses, etc. |
| <a id="stdout" /> `stdout` | `string`\[] | List of strings printed to stdout by prints, subprocesses, etc. |

***

### MIMEType

```ts theme={null}
type MIMEType = string;
```

Represents a MIME type.

***

### RawData

```ts theme={null}
type RawData = object & E2BData;
```

Dictionary that maps MIME types to their corresponding representations of the data.

## Functions

### extractError()

```ts theme={null}
function extractError(res: Response): Promise<undefined | SandboxError>
```

#### Parameters

| Parameter | Type       |
| --------- | ---------- |
| `res`     | `Response` |

#### Returns

`Promise`\<`undefined` | `SandboxError`>

***

### parseOutput()

```ts theme={null}
function parseOutput(
   execution: Execution, 
   line: string, 
   onStdout?: (output: OutputMessage) => any, 
   onStderr?: (output: OutputMessage) => any, 
   onResult?: (data: Result) => any, 
onError?: (error: ExecutionError) => any): Promise<void>
```

#### Parameters

| Parameter   | Type                                 |
| ----------- | ------------------------------------ |
| `execution` | `Execution`                          |
| `line`      | `string`                             |
| `onStdout`? | (`output`: `OutputMessage`) => `any` |
| `onStderr`? | (`output`: `OutputMessage`) => `any` |
| `onResult`? | (`data`: `Result`) => `any`          |
| `onError`?  | (`error`: `ExecutionError`) => `any` |

#### Returns

`Promise`\<`void`>
