@e2b/code-interpreter 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -339,6 +339,9 @@ var Sandbox = class extends import_e2b3.Sandbox {
339
339
  const headers = {
340
340
  "Content-Type": "application/json"
341
341
  };
342
+ if (this.trafficAccessToken) {
343
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
344
+ }
342
345
  if (this.envdAccessToken) {
343
346
  headers["X-Access-Token"] = this.envdAccessToken;
344
347
  }
@@ -412,11 +415,15 @@ var Sandbox = class extends import_e2b3.Sandbox {
412
415
  */
413
416
  async createCodeContext(opts) {
414
417
  try {
418
+ const headers = {
419
+ "Content-Type": "application/json"
420
+ };
421
+ if (this.trafficAccessToken) {
422
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
423
+ }
415
424
  const res = await fetch(`${this.jupyterUrl}/contexts`, {
416
425
  method: "POST",
417
- headers: __spreadValues({
418
- "Content-Type": "application/json"
419
- }, this.connectionConfig.headers),
426
+ headers,
420
427
  body: JSON.stringify({
421
428
  language: opts == null ? void 0 : opts.language,
422
429
  cwd: opts == null ? void 0 : opts.cwd
@@ -443,11 +450,15 @@ var Sandbox = class extends import_e2b3.Sandbox {
443
450
  async removeCodeContext(context) {
444
451
  try {
445
452
  const id = typeof context === "string" ? context : context.id;
453
+ const headers = {
454
+ "Content-Type": "application/json"
455
+ };
456
+ if (this.trafficAccessToken) {
457
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
458
+ }
446
459
  const res = await fetch(`${this.jupyterUrl}/contexts/${id}`, {
447
460
  method: "DELETE",
448
- headers: __spreadValues({
449
- "Content-Type": "application/json"
450
- }, this.connectionConfig.headers),
461
+ headers,
451
462
  keepalive: true,
452
463
  signal: this.connectionConfig.getSignal(
453
464
  this.connectionConfig.requestTimeoutMs
@@ -468,11 +479,15 @@ var Sandbox = class extends import_e2b3.Sandbox {
468
479
  */
469
480
  async listCodeContexts() {
470
481
  try {
482
+ const headers = {
483
+ "Content-Type": "application/json"
484
+ };
485
+ if (this.trafficAccessToken) {
486
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
487
+ }
471
488
  const res = await fetch(`${this.jupyterUrl}/contexts`, {
472
489
  method: "GET",
473
- headers: __spreadValues({
474
- "Content-Type": "application/json"
475
- }, this.connectionConfig.headers),
490
+ headers,
476
491
  keepalive: true,
477
492
  signal: this.connectionConfig.getSignal(
478
493
  this.connectionConfig.requestTimeoutMs
@@ -497,11 +512,15 @@ var Sandbox = class extends import_e2b3.Sandbox {
497
512
  async restartCodeContext(context) {
498
513
  try {
499
514
  const id = typeof context === "string" ? context : context.id;
515
+ const headers = {
516
+ "Content-Type": "application/json"
517
+ };
518
+ if (this.trafficAccessToken) {
519
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
520
+ }
500
521
  const res = await fetch(`${this.jupyterUrl}/contexts/${id}/restart`, {
501
522
  method: "POST",
502
- headers: __spreadValues({
503
- "Content-Type": "application/json"
504
- }, this.connectionConfig.headers),
523
+ headers,
505
524
  keepalive: true,
506
525
  signal: this.connectionConfig.getSignal(
507
526
  this.connectionConfig.requestTimeoutMs
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/sandbox.ts","../src/messaging.ts","../src/utils.ts","../src/consts.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { Sandbox } from './sandbox'\nexport type { Context, RunCodeOpts, CreateCodeContextOpts } from './sandbox'\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n ChartType,\n ChartTypes,\n Chart,\n BarChart,\n BarData,\n LineChart,\n ScatterChart,\n BoxAndWhiskerChart,\n BoxAndWhiskerData,\n PieChart,\n PieData,\n SuperChart,\n PointData,\n} from './charts'\nimport { Sandbox } from './sandbox'\n\nexport default Sandbox\n","import { Sandbox as BaseSandbox, InvalidArgumentError } from 'e2b'\n\nimport {\n Result,\n Execution,\n OutputMessage,\n parseOutput,\n extractError,\n ExecutionError,\n} from './messaging'\nimport {\n formatExecutionTimeoutError,\n formatRequestTimeoutError,\n readLines,\n} from './utils'\nimport { JUPYTER_PORT, DEFAULT_TIMEOUT_MS } from './consts'\n\n/**\n * Represents a context for code execution.\n */\nexport type Context = {\n /**\n * The ID of the context.\n */\n id: string\n /**\n * The language of the context.\n */\n language: string\n /**\n * The working directory of the context.\n */\n cwd: string\n}\n\n/**\n * Options for running code.\n */\nexport interface RunCodeOpts {\n /**\n * Callback for handling stdout messages.\n */\n onStdout?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling stderr messages.\n */\n onStderr?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling the final execution result.\n */\n onResult?: (data: Result) => Promise<any> | any\n /**\n * Callback for handling the `ExecutionError` object.\n */\n onError?: (error: ExecutionError) => Promise<any> | any\n /**\n * Custom environment variables for code execution.\n *\n * @default {}\n */\n envs?: Record<string, string>\n /**\n * Timeout for the code execution in **milliseconds**.\n *\n * @default 60_000 // 60 seconds\n */\n timeoutMs?: number\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * Options for creating a code context.\n */\nexport interface CreateCodeContextOpts {\n /**\n * Working directory for the context.\n *\n * @default /home/user\n */\n cwd?: string\n /**\n * Language for the context.\n *\n * @default python\n */\n language?: string\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * E2B cloud sandbox is a secure and isolated cloud environment.\n *\n * The sandbox allows you to:\n * - Access Linux OS\n * - Create, list, and delete files and directories\n * - Run commands\n * - Run isolated code\n * - Access the internet\n *\n * Check docs [here](https://e2b.dev/docs).\n *\n * Use {@link Sandbox.create} to create a new sandbox.\n *\n * @example\n * ```ts\n * import { Sandbox } from '@e2b/code-interpreter'\n *\n * const sandbox = await Sandbox.create()\n * ```\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string =\n 'code-interpreter-v1'\n\n protected get jupyterUrl(): string {\n return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(\n JUPYTER_PORT\n )}`\n }\n\n /**\n * Run the code as Python.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: 'python'\n }\n ): Promise<Execution>\n /**\n * Run the code for the specified language.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n * If no language is specified, Python is used.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: string\n }\n ): Promise<Execution>\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code\n *\n * @returns `Execution` result object\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Context to run the code in.\n */\n context?: Context\n }\n ): Promise<Execution>\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n language?: string\n context?: Context\n }\n ): Promise<Execution> {\n if (opts?.context && opts?.language) {\n throw new InvalidArgumentError(\n 'You can provide context or language, but not both at the same time.'\n )\n }\n\n const controller = new AbortController()\n\n const requestTimeout =\n opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout\n ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n if (this.envdAccessToken) {\n headers['X-Access-Token'] = this.envdAccessToken\n }\n\n try {\n const res = await fetch(`${this.jupyterUrl}/execute`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n code,\n context_id: opts?.context?.id,\n language: opts?.language,\n env_vars: opts?.envs,\n }),\n signal: controller.signal,\n keepalive: true,\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n if (!res.body) {\n throw new Error(\n `Not response body: ${res.statusText} ${await res?.text()}`\n )\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(\n execution,\n chunk,\n opts?.onStdout,\n opts?.onStderr,\n opts?.onResult,\n opts?.onError\n )\n }\n } catch (error) {\n throw formatExecutionTimeoutError(error)\n } finally {\n clearTimeout(bodyTimer)\n }\n\n return execution\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Creates a new context to run code in.\n *\n * @param opts options for creating the context.\n *\n * @returns context object.\n */\n async createCodeContext(opts?: CreateCodeContextOpts): Promise<Context> {\n try {\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n body: JSON.stringify({\n language: opts?.language,\n cwd: opts?.cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Removes a context.\n *\n * @param context context to remove.\n *\n * @returns void.\n */\n async removeCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}`, {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * List all contexts.\n *\n * @returns list of contexts.\n */\n async listCodeContexts(): Promise<Context[]> {\n try {\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restart a context.\n *\n * @param context context to restart.\n *\n * @returns void.\n */\n async restartCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}/restart`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { ChartTypes } from './charts'\n\nexport async function extractError(res: Response) {\n if (res.ok) {\n return\n }\n\n switch (res.status) {\n case 502:\n return new TimeoutError(\n `${await res.text()}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`\n )\n case 404:\n return new NotFoundError(await res.text())\n default:\n return new SandboxError(`${res.status} ${res.statusText}`)\n }\n}\n\n/**\n * Represents an output message from the sandbox code execution.\n */\nexport class OutputMessage {\n constructor(\n /**\n * The output line.\n */\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds.\n */\n public readonly timestamp: number,\n /**\n * Whether the output is an error.\n */\n public readonly error: boolean\n ) {}\n\n public toString() {\n return this.line\n }\n}\n\n/**\n * Represents an error that occurred during the execution of a cell.\n * The error contains the name of the error, the value of the error, and the traceback.\n */\nexport class ExecutionError {\n constructor(\n /**\n * Name of the error.\n **/\n public name: string,\n /**\n * Value of the error.\n **/\n public value: string,\n /**\n * The raw traceback of the error.\n **/\n public traceback: string\n ) {}\n}\n\n/**\n * Represents a MIME type.\n */\nexport type MIMEType = string\n\ntype E2BData = {\n data: Record<string, unknown>\n chart: ChartTypes\n}\n\n/**\n * Dictionary that maps MIME types to their corresponding representations of the data.\n */\nexport type RawData = {\n [key: MIMEType]: string\n} & E2BData\n\n/**\n * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.\n * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics\n *\n *\n * The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented\n * as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,\n * for the actual result the representation is always present for the result, the other representations are always optional.\n */\nexport class Result {\n /**\n * Text representation of the result.\n */\n readonly text?: string\n /**\n * HTML representation of the data.\n */\n readonly html?: string\n /**\n * Markdown representation of the data.\n */\n readonly markdown?: string\n /**\n * SVG representation of the data.\n */\n readonly svg?: string\n /**\n * PNG representation of the data.\n */\n readonly png?: string\n /**\n * JPEG representation of the data.\n */\n readonly jpeg?: string\n /**\n * PDF representation of the data.\n */\n readonly pdf?: string\n /**\n * LaTeX representation of the data.\n */\n readonly latex?: string\n /**\n * JSON representation of the data.\n */\n readonly json?: string\n /**\n * JavaScript representation of the data.\n */\n readonly javascript?: string\n /**\n * Contains the data from DataFrame.\n */\n readonly data?: Record<string, unknown>\n /**\n * Contains the chart data.\n */\n readonly chart?: ChartTypes\n /**\n * Extra data that can be included. Not part of the standard types.\n */\n readonly extra?: any\n\n readonly raw: RawData\n\n constructor(\n rawData: RawData,\n public readonly isMainResult: boolean\n ) {\n const data = { ...rawData }\n delete data['type']\n delete data['is_main_result']\n\n this.text = data['text']\n this.html = data['html']\n this.markdown = data['markdown']\n this.svg = data['svg']\n this.png = data['png']\n this.jpeg = data['jpeg']\n this.pdf = data['pdf']\n this.latex = data['latex']\n this.json = data['json']\n this.javascript = data['javascript']\n this.isMainResult = isMainResult\n this.raw = data\n\n this.data = data['data']\n this.chart = data['chart']\n\n this.extra = {}\n\n for (const key of Object.keys(data)) {\n if (\n ![\n 'plain',\n 'html',\n 'markdown',\n 'svg',\n 'png',\n 'jpeg',\n 'pdf',\n 'latex',\n 'json',\n 'javascript',\n 'data',\n 'chart',\n 'extra',\n 'text',\n ].includes(key)\n ) {\n this.extra[key] = data[key]\n }\n }\n }\n\n /**\n * Returns all the formats available for the result.\n *\n * @returns Array of strings representing the formats available for the result.\n */\n formats(): string[] {\n const formats = []\n if (this.html) {\n formats.push('html')\n }\n if (this.markdown) {\n formats.push('markdown')\n }\n if (this.svg) {\n formats.push('svg')\n }\n if (this.png) {\n formats.push('png')\n }\n if (this.jpeg) {\n formats.push('jpeg')\n }\n if (this.pdf) {\n formats.push('pdf')\n }\n if (this.latex) {\n formats.push('latex')\n }\n if (this.json) {\n formats.push('json')\n }\n if (this.javascript) {\n formats.push('javascript')\n }\n if (this.data) {\n formats.push('data')\n }\n\n for (const key of Object.keys(this.extra)) {\n formats.push(key)\n }\n\n return formats\n }\n\n /**\n * Returns the serializable representation of the result.\n */\n toJSON() {\n return {\n text: this.text,\n html: this.html,\n markdown: this.markdown,\n svg: this.svg,\n png: this.png,\n jpeg: this.jpeg,\n pdf: this.pdf,\n latex: this.latex,\n json: this.json,\n javascript: this.javascript,\n ...(Object.keys(this.extra).length > 0 ? { extra: this.extra } : {}),\n }\n }\n}\n\n/**\n * Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.\n */\nexport type Logs = {\n /**\n * List of strings printed to stdout by prints, subprocesses, etc.\n */\n stdout: string[]\n /**\n * List of strings printed to stderr by prints, subprocesses, etc.\n */\n stderr: string[]\n}\n\n/**\n * Represents the result of a cell execution.\n */\nexport class Execution {\n constructor(\n /**\n * List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).\n */\n public results: Result[] = [],\n /**\n * Logs printed to stdout and stderr during execution.\n */\n public logs: Logs = { stdout: [], stderr: [] },\n /**\n * An Error object if an error occurred, null otherwise.\n */\n public error?: ExecutionError,\n /**\n * Execution count of the cell.\n */\n public executionCount?: number\n ) {}\n\n /**\n * Returns the text representation of the main result of the cell.\n */\n get text(): string | undefined {\n for (const data of this.results) {\n if (data.isMainResult) {\n return data.text\n }\n }\n }\n\n /**\n * Returns the serializable representation of the execution result.\n */\n toJSON() {\n return {\n results: this.results,\n logs: this.logs,\n error: this.error,\n }\n }\n}\n\nexport async function parseOutput(\n execution: Execution,\n line: string,\n onStdout?: (output: OutputMessage) => Promise<any> | any,\n onStderr?: (output: OutputMessage) => Promise<any> | any,\n onResult?: (data: Result) => Promise<any> | any,\n onError?: (error: ExecutionError) => Promise<any> | any\n) {\n const msg = JSON.parse(line)\n\n switch (msg.type) {\n case 'result': {\n const result = new Result(\n { ...msg, type: undefined, is_main_result: undefined },\n msg.is_main_result\n )\n execution.results.push(result)\n if (onResult) {\n await onResult(result)\n }\n break\n }\n case 'stdout':\n execution.logs.stdout.push(msg.text)\n if (onStdout) {\n await onStdout({\n error: false,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'stderr':\n execution.logs.stderr.push(msg.text)\n if (onStderr) {\n await onStderr({\n error: true,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'error':\n execution.error = new ExecutionError(msg.name, msg.value, msg.traceback)\n if (onError) {\n await onError(execution.error)\n }\n break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n","import { TimeoutError } from 'e2b'\n\nexport function formatRequestTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Request timed out — the 'requestTimeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport function formatExecutionTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Execution timed out — the 'timeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport async function* readLines(stream: ReadableStream<Uint8Array>) {\n const reader = stream.getReader()\n let buffer = ''\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n\n if (value !== undefined) {\n buffer += new TextDecoder().decode(value)\n }\n\n if (done) {\n if (buffer.length > 0) {\n yield buffer\n }\n break\n }\n\n let newlineIdx = -1\n\n do {\n newlineIdx = buffer.indexOf('\\n')\n if (newlineIdx !== -1) {\n yield buffer.slice(0, newlineIdx)\n buffer = buffer.slice(newlineIdx + 1)\n }\n } while (newlineIdx !== -1)\n }\n } finally {\n reader.releaseLock()\n }\n}\n","export const DEFAULT_TIMEOUT_MS = 60_000 // 1 minute\nexport const JUPYTER_PORT = 49999\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,gBAAd;;;ACAA,IAAAA,cAA6D;;;ACA7D,iBAA0D;AAG1D,eAAsB,aAAa,KAAe;AAChD,MAAI,IAAI,IAAI;AACV;AAAA,EACF;AAEA,UAAQ,IAAI,QAAQ;AAAA,IAClB,KAAK;AACH,aAAO,IAAI;AAAA,QACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,MACrB;AAAA,IACF,KAAK;AACH,aAAO,IAAI,yBAAc,MAAM,IAAI,KAAK,CAAC;AAAA,IAC3C;AACE,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BaseSandbox","error"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/sandbox.ts","../src/messaging.ts","../src/utils.ts","../src/consts.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { Sandbox } from './sandbox'\nexport type { Context, RunCodeOpts, CreateCodeContextOpts } from './sandbox'\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n ChartType,\n ChartTypes,\n Chart,\n BarChart,\n BarData,\n LineChart,\n ScatterChart,\n BoxAndWhiskerChart,\n BoxAndWhiskerData,\n PieChart,\n PieData,\n SuperChart,\n PointData,\n} from './charts'\nimport { Sandbox } from './sandbox'\n\nexport default Sandbox\n","import { Sandbox as BaseSandbox, InvalidArgumentError } from 'e2b'\n\nimport {\n Result,\n Execution,\n OutputMessage,\n parseOutput,\n extractError,\n ExecutionError,\n} from './messaging'\nimport {\n formatExecutionTimeoutError,\n formatRequestTimeoutError,\n readLines,\n} from './utils'\nimport { JUPYTER_PORT, DEFAULT_TIMEOUT_MS } from './consts'\n\n/**\n * Represents a context for code execution.\n */\nexport type Context = {\n /**\n * The ID of the context.\n */\n id: string\n /**\n * The language of the context.\n */\n language: string\n /**\n * The working directory of the context.\n */\n cwd: string\n}\n\n/**\n * Options for running code.\n */\nexport interface RunCodeOpts {\n /**\n * Callback for handling stdout messages.\n */\n onStdout?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling stderr messages.\n */\n onStderr?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling the final execution result.\n */\n onResult?: (data: Result) => Promise<any> | any\n /**\n * Callback for handling the `ExecutionError` object.\n */\n onError?: (error: ExecutionError) => Promise<any> | any\n /**\n * Custom environment variables for code execution.\n *\n * @default {}\n */\n envs?: Record<string, string>\n /**\n * Timeout for the code execution in **milliseconds**.\n *\n * @default 60_000 // 60 seconds\n */\n timeoutMs?: number\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * Options for creating a code context.\n */\nexport interface CreateCodeContextOpts {\n /**\n * Working directory for the context.\n *\n * @default /home/user\n */\n cwd?: string\n /**\n * Language for the context.\n *\n * @default python\n */\n language?: string\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * E2B cloud sandbox is a secure and isolated cloud environment.\n *\n * The sandbox allows you to:\n * - Access Linux OS\n * - Create, list, and delete files and directories\n * - Run commands\n * - Run isolated code\n * - Access the internet\n *\n * Check docs [here](https://e2b.dev/docs).\n *\n * Use {@link Sandbox.create} to create a new sandbox.\n *\n * @example\n * ```ts\n * import { Sandbox } from '@e2b/code-interpreter'\n *\n * const sandbox = await Sandbox.create()\n * ```\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string =\n 'code-interpreter-v1'\n\n protected get jupyterUrl(): string {\n return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(\n JUPYTER_PORT\n )}`\n }\n\n /**\n * Run the code as Python.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: 'python'\n }\n ): Promise<Execution>\n /**\n * Run the code for the specified language.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n * If no language is specified, Python is used.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: string\n }\n ): Promise<Execution>\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code\n *\n * @returns `Execution` result object\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Context to run the code in.\n */\n context?: Context\n }\n ): Promise<Execution>\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n language?: string\n context?: Context\n }\n ): Promise<Execution> {\n if (opts?.context && opts?.language) {\n throw new InvalidArgumentError(\n 'You can provide context or language, but not both at the same time.'\n )\n }\n\n const controller = new AbortController()\n\n const requestTimeout =\n opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout\n ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n if (this.envdAccessToken) {\n headers['X-Access-Token'] = this.envdAccessToken\n }\n\n try {\n const res = await fetch(`${this.jupyterUrl}/execute`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n code,\n context_id: opts?.context?.id,\n language: opts?.language,\n env_vars: opts?.envs,\n }),\n signal: controller.signal,\n keepalive: true,\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n if (!res.body) {\n throw new Error(\n `Not response body: ${res.statusText} ${await res?.text()}`\n )\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(\n execution,\n chunk,\n opts?.onStdout,\n opts?.onStderr,\n opts?.onResult,\n opts?.onError\n )\n }\n } catch (error) {\n throw formatExecutionTimeoutError(error)\n } finally {\n clearTimeout(bodyTimer)\n }\n\n return execution\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Creates a new context to run code in.\n *\n * @param opts options for creating the context.\n *\n * @returns context object.\n */\n async createCodeContext(opts?: CreateCodeContextOpts): Promise<Context> {\n try {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n language: opts?.language,\n cwd: opts?.cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Removes a context.\n *\n * @param context context to remove.\n *\n * @returns void.\n */\n async removeCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}`, {\n method: 'DELETE',\n headers,\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * List all contexts.\n *\n * @returns list of contexts.\n */\n async listCodeContexts(): Promise<Context[]> {\n try {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'GET',\n headers,\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restart a context.\n *\n * @param context context to restart.\n *\n * @returns void.\n */\n async restartCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}/restart`, {\n method: 'POST',\n headers,\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { ChartTypes } from './charts'\n\nexport async function extractError(res: Response) {\n if (res.ok) {\n return\n }\n\n switch (res.status) {\n case 502:\n return new TimeoutError(\n `${await res.text()}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`\n )\n case 404:\n return new NotFoundError(await res.text())\n default:\n return new SandboxError(`${res.status} ${res.statusText}`)\n }\n}\n\n/**\n * Represents an output message from the sandbox code execution.\n */\nexport class OutputMessage {\n constructor(\n /**\n * The output line.\n */\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds.\n */\n public readonly timestamp: number,\n /**\n * Whether the output is an error.\n */\n public readonly error: boolean\n ) {}\n\n public toString() {\n return this.line\n }\n}\n\n/**\n * Represents an error that occurred during the execution of a cell.\n * The error contains the name of the error, the value of the error, and the traceback.\n */\nexport class ExecutionError {\n constructor(\n /**\n * Name of the error.\n **/\n public name: string,\n /**\n * Value of the error.\n **/\n public value: string,\n /**\n * The raw traceback of the error.\n **/\n public traceback: string\n ) {}\n}\n\n/**\n * Represents a MIME type.\n */\nexport type MIMEType = string\n\ntype E2BData = {\n data: Record<string, unknown>\n chart: ChartTypes\n}\n\n/**\n * Dictionary that maps MIME types to their corresponding representations of the data.\n */\nexport type RawData = {\n [key: MIMEType]: string\n} & E2BData\n\n/**\n * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.\n * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics\n *\n *\n * The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented\n * as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,\n * for the actual result the representation is always present for the result, the other representations are always optional.\n */\nexport class Result {\n /**\n * Text representation of the result.\n */\n readonly text?: string\n /**\n * HTML representation of the data.\n */\n readonly html?: string\n /**\n * Markdown representation of the data.\n */\n readonly markdown?: string\n /**\n * SVG representation of the data.\n */\n readonly svg?: string\n /**\n * PNG representation of the data.\n */\n readonly png?: string\n /**\n * JPEG representation of the data.\n */\n readonly jpeg?: string\n /**\n * PDF representation of the data.\n */\n readonly pdf?: string\n /**\n * LaTeX representation of the data.\n */\n readonly latex?: string\n /**\n * JSON representation of the data.\n */\n readonly json?: string\n /**\n * JavaScript representation of the data.\n */\n readonly javascript?: string\n /**\n * Contains the data from DataFrame.\n */\n readonly data?: Record<string, unknown>\n /**\n * Contains the chart data.\n */\n readonly chart?: ChartTypes\n /**\n * Extra data that can be included. Not part of the standard types.\n */\n readonly extra?: any\n\n readonly raw: RawData\n\n constructor(\n rawData: RawData,\n public readonly isMainResult: boolean\n ) {\n const data = { ...rawData }\n delete data['type']\n delete data['is_main_result']\n\n this.text = data['text']\n this.html = data['html']\n this.markdown = data['markdown']\n this.svg = data['svg']\n this.png = data['png']\n this.jpeg = data['jpeg']\n this.pdf = data['pdf']\n this.latex = data['latex']\n this.json = data['json']\n this.javascript = data['javascript']\n this.isMainResult = isMainResult\n this.raw = data\n\n this.data = data['data']\n this.chart = data['chart']\n\n this.extra = {}\n\n for (const key of Object.keys(data)) {\n if (\n ![\n 'plain',\n 'html',\n 'markdown',\n 'svg',\n 'png',\n 'jpeg',\n 'pdf',\n 'latex',\n 'json',\n 'javascript',\n 'data',\n 'chart',\n 'extra',\n 'text',\n ].includes(key)\n ) {\n this.extra[key] = data[key]\n }\n }\n }\n\n /**\n * Returns all the formats available for the result.\n *\n * @returns Array of strings representing the formats available for the result.\n */\n formats(): string[] {\n const formats = []\n if (this.html) {\n formats.push('html')\n }\n if (this.markdown) {\n formats.push('markdown')\n }\n if (this.svg) {\n formats.push('svg')\n }\n if (this.png) {\n formats.push('png')\n }\n if (this.jpeg) {\n formats.push('jpeg')\n }\n if (this.pdf) {\n formats.push('pdf')\n }\n if (this.latex) {\n formats.push('latex')\n }\n if (this.json) {\n formats.push('json')\n }\n if (this.javascript) {\n formats.push('javascript')\n }\n if (this.data) {\n formats.push('data')\n }\n\n for (const key of Object.keys(this.extra)) {\n formats.push(key)\n }\n\n return formats\n }\n\n /**\n * Returns the serializable representation of the result.\n */\n toJSON() {\n return {\n text: this.text,\n html: this.html,\n markdown: this.markdown,\n svg: this.svg,\n png: this.png,\n jpeg: this.jpeg,\n pdf: this.pdf,\n latex: this.latex,\n json: this.json,\n javascript: this.javascript,\n ...(Object.keys(this.extra).length > 0 ? { extra: this.extra } : {}),\n }\n }\n}\n\n/**\n * Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.\n */\nexport type Logs = {\n /**\n * List of strings printed to stdout by prints, subprocesses, etc.\n */\n stdout: string[]\n /**\n * List of strings printed to stderr by prints, subprocesses, etc.\n */\n stderr: string[]\n}\n\n/**\n * Represents the result of a cell execution.\n */\nexport class Execution {\n constructor(\n /**\n * List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).\n */\n public results: Result[] = [],\n /**\n * Logs printed to stdout and stderr during execution.\n */\n public logs: Logs = { stdout: [], stderr: [] },\n /**\n * An Error object if an error occurred, null otherwise.\n */\n public error?: ExecutionError,\n /**\n * Execution count of the cell.\n */\n public executionCount?: number\n ) {}\n\n /**\n * Returns the text representation of the main result of the cell.\n */\n get text(): string | undefined {\n for (const data of this.results) {\n if (data.isMainResult) {\n return data.text\n }\n }\n }\n\n /**\n * Returns the serializable representation of the execution result.\n */\n toJSON() {\n return {\n results: this.results,\n logs: this.logs,\n error: this.error,\n }\n }\n}\n\nexport async function parseOutput(\n execution: Execution,\n line: string,\n onStdout?: (output: OutputMessage) => Promise<any> | any,\n onStderr?: (output: OutputMessage) => Promise<any> | any,\n onResult?: (data: Result) => Promise<any> | any,\n onError?: (error: ExecutionError) => Promise<any> | any\n) {\n const msg = JSON.parse(line)\n\n switch (msg.type) {\n case 'result': {\n const result = new Result(\n { ...msg, type: undefined, is_main_result: undefined },\n msg.is_main_result\n )\n execution.results.push(result)\n if (onResult) {\n await onResult(result)\n }\n break\n }\n case 'stdout':\n execution.logs.stdout.push(msg.text)\n if (onStdout) {\n await onStdout({\n error: false,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'stderr':\n execution.logs.stderr.push(msg.text)\n if (onStderr) {\n await onStderr({\n error: true,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'error':\n execution.error = new ExecutionError(msg.name, msg.value, msg.traceback)\n if (onError) {\n await onError(execution.error)\n }\n break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n","import { TimeoutError } from 'e2b'\n\nexport function formatRequestTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Request timed out — the 'requestTimeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport function formatExecutionTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Execution timed out — the 'timeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport async function* readLines(stream: ReadableStream<Uint8Array>) {\n const reader = stream.getReader()\n let buffer = ''\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n\n if (value !== undefined) {\n buffer += new TextDecoder().decode(value)\n }\n\n if (done) {\n if (buffer.length > 0) {\n yield buffer\n }\n break\n }\n\n let newlineIdx = -1\n\n do {\n newlineIdx = buffer.indexOf('\\n')\n if (newlineIdx !== -1) {\n yield buffer.slice(0, newlineIdx)\n buffer = buffer.slice(newlineIdx + 1)\n }\n } while (newlineIdx !== -1)\n }\n } finally {\n reader.releaseLock()\n }\n}\n","export const DEFAULT_TIMEOUT_MS = 60_000 // 1 minute\nexport const JUPYTER_PORT = 49999\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,gBAAd;;;ACAA,IAAAA,cAA6D;;;ACA7D,iBAA0D;AAG1D,eAAsB,aAAa,KAAe;AAChD,MAAI,IAAI,IAAI;AACV;AAAA,EACF;AAEA,UAAQ,IAAI,QAAQ;AAAA,IAClB,KAAK;AACH,aAAO,IAAI;AAAA,QACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,MACrB;AAAA,IACF,KAAK;AACH,aAAO,IAAI,yBAAc,MAAM,IAAI,KAAK,CAAC;AAAA,IAC3C;AACE,aAAO,IAAI,wBAAa,GAAG,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,EAC7D;AACF;AA8BO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YAIS,MAIA,OAIA,WACP;AATO;AAIA;AAIA;AAAA,EACN;AACL;AA4BO,IAAM,SAAN,MAAa;AAAA,EAwDlB,YACE,SACgB,cAChB;AADgB;AAEhB,UAAM,OAAO,mBAAK;AAClB,WAAO,KAAK,MAAM;AAClB,WAAO,KAAK,gBAAgB;AAE5B,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,WAAW,KAAK,UAAU;AAC/B,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,MAAM,KAAK,KAAK;AACr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A,MAClB;AAEA,UAAI,KAAK,oBAAoB;AAC3B,gBAAQ,0BAA0B,IAAI,KAAK;AAAA,MAC7C;AAEA,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK,UAAU,aAAa;AAAA,QACrD,QAAQ;AAAA,QACR;AAAA,QACA,WAAW;AAAA,QACX,QAAQ,KAAK,iBAAiB;AAAA,UAC5B,KAAK,iBAAiB;AAAA,QACxB;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,aAAa,GAAG;AACpC,UAAI,OAAO;AACT,cAAM;AAAA,MACR;AAEA,aAAO,MAAM,IAAI,KAAK;AAAA,IACxB,SAAS,OAAO;AACd,YAAM,0BAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,mBAAmB,SAA0C;AACjE,QAAI;AACF,YAAM,KAAK,OAAO,YAAY,WAAW,UAAU,QAAQ;AAC3D,YAAM,UAAkC;AAAA,QACtC,gBAAgB;AAAA,MAClB;AAEA,UAAI,KAAK,oBAAoB;AAC3B,gBAAQ,0BAA0B,IAAI,KAAK;AAAA,MAC7C;AAEA,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK,UAAU,aAAa,EAAE,YAAY;AAAA,QACnE,QAAQ;AAAA,QACR;AAAA,QACA,WAAW;AAAA,QACX,QAAQ,KAAK,iBAAiB;AAAA,UAC5B,KAAK,iBAAiB;AAAA,QACxB;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,aAAa,GAAG;AACpC,UAAI,OAAO;AACT,cAAM;AAAA,MACR;AAAA,IACF,SAAS,OAAO;AACd,YAAM,0BAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AACF;AA9Ta,QACwB,kBACjC;;;AD3FJ,IAAO,cAAQ;","names":["import_e2b","import_e2b","BaseSandbox","error"]}
package/dist/index.mjs CHANGED
@@ -316,6 +316,9 @@ var Sandbox = class extends BaseSandbox {
316
316
  const headers = {
317
317
  "Content-Type": "application/json"
318
318
  };
319
+ if (this.trafficAccessToken) {
320
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
321
+ }
319
322
  if (this.envdAccessToken) {
320
323
  headers["X-Access-Token"] = this.envdAccessToken;
321
324
  }
@@ -389,11 +392,15 @@ var Sandbox = class extends BaseSandbox {
389
392
  */
390
393
  async createCodeContext(opts) {
391
394
  try {
395
+ const headers = {
396
+ "Content-Type": "application/json"
397
+ };
398
+ if (this.trafficAccessToken) {
399
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
400
+ }
392
401
  const res = await fetch(`${this.jupyterUrl}/contexts`, {
393
402
  method: "POST",
394
- headers: __spreadValues({
395
- "Content-Type": "application/json"
396
- }, this.connectionConfig.headers),
403
+ headers,
397
404
  body: JSON.stringify({
398
405
  language: opts == null ? void 0 : opts.language,
399
406
  cwd: opts == null ? void 0 : opts.cwd
@@ -420,11 +427,15 @@ var Sandbox = class extends BaseSandbox {
420
427
  async removeCodeContext(context) {
421
428
  try {
422
429
  const id = typeof context === "string" ? context : context.id;
430
+ const headers = {
431
+ "Content-Type": "application/json"
432
+ };
433
+ if (this.trafficAccessToken) {
434
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
435
+ }
423
436
  const res = await fetch(`${this.jupyterUrl}/contexts/${id}`, {
424
437
  method: "DELETE",
425
- headers: __spreadValues({
426
- "Content-Type": "application/json"
427
- }, this.connectionConfig.headers),
438
+ headers,
428
439
  keepalive: true,
429
440
  signal: this.connectionConfig.getSignal(
430
441
  this.connectionConfig.requestTimeoutMs
@@ -445,11 +456,15 @@ var Sandbox = class extends BaseSandbox {
445
456
  */
446
457
  async listCodeContexts() {
447
458
  try {
459
+ const headers = {
460
+ "Content-Type": "application/json"
461
+ };
462
+ if (this.trafficAccessToken) {
463
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
464
+ }
448
465
  const res = await fetch(`${this.jupyterUrl}/contexts`, {
449
466
  method: "GET",
450
- headers: __spreadValues({
451
- "Content-Type": "application/json"
452
- }, this.connectionConfig.headers),
467
+ headers,
453
468
  keepalive: true,
454
469
  signal: this.connectionConfig.getSignal(
455
470
  this.connectionConfig.requestTimeoutMs
@@ -474,11 +489,15 @@ var Sandbox = class extends BaseSandbox {
474
489
  async restartCodeContext(context) {
475
490
  try {
476
491
  const id = typeof context === "string" ? context : context.id;
492
+ const headers = {
493
+ "Content-Type": "application/json"
494
+ };
495
+ if (this.trafficAccessToken) {
496
+ headers["E2B-Traffic-Access-Token"] = this.trafficAccessToken;
497
+ }
477
498
  const res = await fetch(`${this.jupyterUrl}/contexts/${id}/restart`, {
478
499
  method: "POST",
479
- headers: __spreadValues({
480
- "Content-Type": "application/json"
481
- }, this.connectionConfig.headers),
500
+ headers,
482
501
  keepalive: true,
483
502
  signal: this.connectionConfig.getSignal(
484
503
  this.connectionConfig.requestTimeoutMs
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/sandbox.ts","../src/messaging.ts","../src/utils.ts","../src/consts.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { Sandbox } from './sandbox'\nexport type { Context, RunCodeOpts, CreateCodeContextOpts } from './sandbox'\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n ChartType,\n ChartTypes,\n Chart,\n BarChart,\n BarData,\n LineChart,\n ScatterChart,\n BoxAndWhiskerChart,\n BoxAndWhiskerData,\n PieChart,\n PieData,\n SuperChart,\n PointData,\n} from './charts'\nimport { Sandbox } from './sandbox'\n\nexport default Sandbox\n","import { Sandbox as BaseSandbox, InvalidArgumentError } from 'e2b'\n\nimport {\n Result,\n Execution,\n OutputMessage,\n parseOutput,\n extractError,\n ExecutionError,\n} from './messaging'\nimport {\n formatExecutionTimeoutError,\n formatRequestTimeoutError,\n readLines,\n} from './utils'\nimport { JUPYTER_PORT, DEFAULT_TIMEOUT_MS } from './consts'\n\n/**\n * Represents a context for code execution.\n */\nexport type Context = {\n /**\n * The ID of the context.\n */\n id: string\n /**\n * The language of the context.\n */\n language: string\n /**\n * The working directory of the context.\n */\n cwd: string\n}\n\n/**\n * Options for running code.\n */\nexport interface RunCodeOpts {\n /**\n * Callback for handling stdout messages.\n */\n onStdout?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling stderr messages.\n */\n onStderr?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling the final execution result.\n */\n onResult?: (data: Result) => Promise<any> | any\n /**\n * Callback for handling the `ExecutionError` object.\n */\n onError?: (error: ExecutionError) => Promise<any> | any\n /**\n * Custom environment variables for code execution.\n *\n * @default {}\n */\n envs?: Record<string, string>\n /**\n * Timeout for the code execution in **milliseconds**.\n *\n * @default 60_000 // 60 seconds\n */\n timeoutMs?: number\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * Options for creating a code context.\n */\nexport interface CreateCodeContextOpts {\n /**\n * Working directory for the context.\n *\n * @default /home/user\n */\n cwd?: string\n /**\n * Language for the context.\n *\n * @default python\n */\n language?: string\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * E2B cloud sandbox is a secure and isolated cloud environment.\n *\n * The sandbox allows you to:\n * - Access Linux OS\n * - Create, list, and delete files and directories\n * - Run commands\n * - Run isolated code\n * - Access the internet\n *\n * Check docs [here](https://e2b.dev/docs).\n *\n * Use {@link Sandbox.create} to create a new sandbox.\n *\n * @example\n * ```ts\n * import { Sandbox } from '@e2b/code-interpreter'\n *\n * const sandbox = await Sandbox.create()\n * ```\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string =\n 'code-interpreter-v1'\n\n protected get jupyterUrl(): string {\n return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(\n JUPYTER_PORT\n )}`\n }\n\n /**\n * Run the code as Python.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: 'python'\n }\n ): Promise<Execution>\n /**\n * Run the code for the specified language.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n * If no language is specified, Python is used.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: string\n }\n ): Promise<Execution>\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code\n *\n * @returns `Execution` result object\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Context to run the code in.\n */\n context?: Context\n }\n ): Promise<Execution>\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n language?: string\n context?: Context\n }\n ): Promise<Execution> {\n if (opts?.context && opts?.language) {\n throw new InvalidArgumentError(\n 'You can provide context or language, but not both at the same time.'\n )\n }\n\n const controller = new AbortController()\n\n const requestTimeout =\n opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout\n ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n if (this.envdAccessToken) {\n headers['X-Access-Token'] = this.envdAccessToken\n }\n\n try {\n const res = await fetch(`${this.jupyterUrl}/execute`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n code,\n context_id: opts?.context?.id,\n language: opts?.language,\n env_vars: opts?.envs,\n }),\n signal: controller.signal,\n keepalive: true,\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n if (!res.body) {\n throw new Error(\n `Not response body: ${res.statusText} ${await res?.text()}`\n )\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(\n execution,\n chunk,\n opts?.onStdout,\n opts?.onStderr,\n opts?.onResult,\n opts?.onError\n )\n }\n } catch (error) {\n throw formatExecutionTimeoutError(error)\n } finally {\n clearTimeout(bodyTimer)\n }\n\n return execution\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Creates a new context to run code in.\n *\n * @param opts options for creating the context.\n *\n * @returns context object.\n */\n async createCodeContext(opts?: CreateCodeContextOpts): Promise<Context> {\n try {\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n body: JSON.stringify({\n language: opts?.language,\n cwd: opts?.cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Removes a context.\n *\n * @param context context to remove.\n *\n * @returns void.\n */\n async removeCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}`, {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * List all contexts.\n *\n * @returns list of contexts.\n */\n async listCodeContexts(): Promise<Context[]> {\n try {\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restart a context.\n *\n * @param context context to restart.\n *\n * @returns void.\n */\n async restartCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}/restart`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { ChartTypes } from './charts'\n\nexport async function extractError(res: Response) {\n if (res.ok) {\n return\n }\n\n switch (res.status) {\n case 502:\n return new TimeoutError(\n `${await res.text()}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`\n )\n case 404:\n return new NotFoundError(await res.text())\n default:\n return new SandboxError(`${res.status} ${res.statusText}`)\n }\n}\n\n/**\n * Represents an output message from the sandbox code execution.\n */\nexport class OutputMessage {\n constructor(\n /**\n * The output line.\n */\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds.\n */\n public readonly timestamp: number,\n /**\n * Whether the output is an error.\n */\n public readonly error: boolean\n ) {}\n\n public toString() {\n return this.line\n }\n}\n\n/**\n * Represents an error that occurred during the execution of a cell.\n * The error contains the name of the error, the value of the error, and the traceback.\n */\nexport class ExecutionError {\n constructor(\n /**\n * Name of the error.\n **/\n public name: string,\n /**\n * Value of the error.\n **/\n public value: string,\n /**\n * The raw traceback of the error.\n **/\n public traceback: string\n ) {}\n}\n\n/**\n * Represents a MIME type.\n */\nexport type MIMEType = string\n\ntype E2BData = {\n data: Record<string, unknown>\n chart: ChartTypes\n}\n\n/**\n * Dictionary that maps MIME types to their corresponding representations of the data.\n */\nexport type RawData = {\n [key: MIMEType]: string\n} & E2BData\n\n/**\n * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.\n * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics\n *\n *\n * The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented\n * as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,\n * for the actual result the representation is always present for the result, the other representations are always optional.\n */\nexport class Result {\n /**\n * Text representation of the result.\n */\n readonly text?: string\n /**\n * HTML representation of the data.\n */\n readonly html?: string\n /**\n * Markdown representation of the data.\n */\n readonly markdown?: string\n /**\n * SVG representation of the data.\n */\n readonly svg?: string\n /**\n * PNG representation of the data.\n */\n readonly png?: string\n /**\n * JPEG representation of the data.\n */\n readonly jpeg?: string\n /**\n * PDF representation of the data.\n */\n readonly pdf?: string\n /**\n * LaTeX representation of the data.\n */\n readonly latex?: string\n /**\n * JSON representation of the data.\n */\n readonly json?: string\n /**\n * JavaScript representation of the data.\n */\n readonly javascript?: string\n /**\n * Contains the data from DataFrame.\n */\n readonly data?: Record<string, unknown>\n /**\n * Contains the chart data.\n */\n readonly chart?: ChartTypes\n /**\n * Extra data that can be included. Not part of the standard types.\n */\n readonly extra?: any\n\n readonly raw: RawData\n\n constructor(\n rawData: RawData,\n public readonly isMainResult: boolean\n ) {\n const data = { ...rawData }\n delete data['type']\n delete data['is_main_result']\n\n this.text = data['text']\n this.html = data['html']\n this.markdown = data['markdown']\n this.svg = data['svg']\n this.png = data['png']\n this.jpeg = data['jpeg']\n this.pdf = data['pdf']\n this.latex = data['latex']\n this.json = data['json']\n this.javascript = data['javascript']\n this.isMainResult = isMainResult\n this.raw = data\n\n this.data = data['data']\n this.chart = data['chart']\n\n this.extra = {}\n\n for (const key of Object.keys(data)) {\n if (\n ![\n 'plain',\n 'html',\n 'markdown',\n 'svg',\n 'png',\n 'jpeg',\n 'pdf',\n 'latex',\n 'json',\n 'javascript',\n 'data',\n 'chart',\n 'extra',\n 'text',\n ].includes(key)\n ) {\n this.extra[key] = data[key]\n }\n }\n }\n\n /**\n * Returns all the formats available for the result.\n *\n * @returns Array of strings representing the formats available for the result.\n */\n formats(): string[] {\n const formats = []\n if (this.html) {\n formats.push('html')\n }\n if (this.markdown) {\n formats.push('markdown')\n }\n if (this.svg) {\n formats.push('svg')\n }\n if (this.png) {\n formats.push('png')\n }\n if (this.jpeg) {\n formats.push('jpeg')\n }\n if (this.pdf) {\n formats.push('pdf')\n }\n if (this.latex) {\n formats.push('latex')\n }\n if (this.json) {\n formats.push('json')\n }\n if (this.javascript) {\n formats.push('javascript')\n }\n if (this.data) {\n formats.push('data')\n }\n\n for (const key of Object.keys(this.extra)) {\n formats.push(key)\n }\n\n return formats\n }\n\n /**\n * Returns the serializable representation of the result.\n */\n toJSON() {\n return {\n text: this.text,\n html: this.html,\n markdown: this.markdown,\n svg: this.svg,\n png: this.png,\n jpeg: this.jpeg,\n pdf: this.pdf,\n latex: this.latex,\n json: this.json,\n javascript: this.javascript,\n ...(Object.keys(this.extra).length > 0 ? { extra: this.extra } : {}),\n }\n }\n}\n\n/**\n * Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.\n */\nexport type Logs = {\n /**\n * List of strings printed to stdout by prints, subprocesses, etc.\n */\n stdout: string[]\n /**\n * List of strings printed to stderr by prints, subprocesses, etc.\n */\n stderr: string[]\n}\n\n/**\n * Represents the result of a cell execution.\n */\nexport class Execution {\n constructor(\n /**\n * List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).\n */\n public results: Result[] = [],\n /**\n * Logs printed to stdout and stderr during execution.\n */\n public logs: Logs = { stdout: [], stderr: [] },\n /**\n * An Error object if an error occurred, null otherwise.\n */\n public error?: ExecutionError,\n /**\n * Execution count of the cell.\n */\n public executionCount?: number\n ) {}\n\n /**\n * Returns the text representation of the main result of the cell.\n */\n get text(): string | undefined {\n for (const data of this.results) {\n if (data.isMainResult) {\n return data.text\n }\n }\n }\n\n /**\n * Returns the serializable representation of the execution result.\n */\n toJSON() {\n return {\n results: this.results,\n logs: this.logs,\n error: this.error,\n }\n }\n}\n\nexport async function parseOutput(\n execution: Execution,\n line: string,\n onStdout?: (output: OutputMessage) => Promise<any> | any,\n onStderr?: (output: OutputMessage) => Promise<any> | any,\n onResult?: (data: Result) => Promise<any> | any,\n onError?: (error: ExecutionError) => Promise<any> | any\n) {\n const msg = JSON.parse(line)\n\n switch (msg.type) {\n case 'result': {\n const result = new Result(\n { ...msg, type: undefined, is_main_result: undefined },\n msg.is_main_result\n )\n execution.results.push(result)\n if (onResult) {\n await onResult(result)\n }\n break\n }\n case 'stdout':\n execution.logs.stdout.push(msg.text)\n if (onStdout) {\n await onStdout({\n error: false,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'stderr':\n execution.logs.stderr.push(msg.text)\n if (onStderr) {\n await onStderr({\n error: true,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'error':\n execution.error = new ExecutionError(msg.name, msg.value, msg.traceback)\n if (onError) {\n await onError(execution.error)\n }\n break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n","import { TimeoutError } from 'e2b'\n\nexport function formatRequestTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Request timed out — the 'requestTimeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport function formatExecutionTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Execution timed out — the 'timeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport async function* readLines(stream: ReadableStream<Uint8Array>) {\n const reader = stream.getReader()\n let buffer = ''\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n\n if (value !== undefined) {\n buffer += new TextDecoder().decode(value)\n }\n\n if (done) {\n if (buffer.length > 0) {\n yield buffer\n }\n break\n }\n\n let newlineIdx = -1\n\n do {\n newlineIdx = buffer.indexOf('\\n')\n if (newlineIdx !== -1) {\n yield buffer.slice(0, newlineIdx)\n buffer = buffer.slice(newlineIdx + 1)\n }\n } while (newlineIdx !== -1)\n }\n } finally {\n reader.releaseLock()\n }\n}\n","export const DEFAULT_TIMEOUT_MS = 60_000 // 1 minute\nexport const JUPYTER_PORT = 49999\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;;;ACAd,SAAS,WAAW,aAAa,4BAA4B;;;ACA7D,SAAS,eAAe,cAAc,oBAAoB;AAG1D,eAAsB,aAAa,KAAe;AAChD,MAAI,IAAI,IAAI;AACV;AAAA,EACF;AAEA,UAAQ,IAAI,QAAQ;AAAA,IAClB,KAAK;AACH,aAAO,IAAI;AAAA,QACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,MACrB;AAAA,IACF,KAAK;AACH,aAAO,IAAI,cAAc,MAAM,IAAI,KAAK,CAAC;AAAA,IAC3C;AACE,aAAO,IAAI,aAAa,GAAG,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,EAC7D;AACF;AA8BO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YAIS,MAIA,OAIA,WACP;AATO;AAIA;AAIA;AAAA,EACN;AACL;AA4BO,IAAM,SAAN,MAAa;AAAA,EAwDlB,YACE,SACgB,cAChB;AADgB;AAEhB,UAAM,OAAO,mBAAK;AAClB,WAAO,KAA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;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,WACb,KAAK,iBAAiB;AAAA,QAE3B,WAAW;AAAA,QACX,QAAQ,KAAK,iBAAiB;AAAA,UAC5B,KAAK,iBAAiB;AAAA,QACxB;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,aAAa,GAAG;AACpC,UAAI,OAAO;AACT,cAAM;AAAA,MACR;AAEA,aAAO,MAAM,IAAI,KAAK;AAAA,IACxB,SAAS,OAAO;AACd,YAAM,0BAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,mBAAmB,SAA0C;AACjE,QAAI;AACF,YAAM,KAAK,OAAO,YAAY,WAAW,UAAU,QAAQ;AAC3D,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK,UAAU,aAAa,EAAE,YAAY;AAAA,QACnE,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,WACb,KAAK,iBAAiB;AAAA,QAE3B,WAAW;AAAA,QACX,QAAQ,KAAK,iBAAiB;AAAA,UAC5B,KAAK,iBAAiB;AAAA,QACxB;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,aAAa,GAAG;AACpC,UAAI,OAAO;AACT,cAAM;AAAA,MACR;AAAA,IACF,SAAS,OAAO;AACd,YAAM,0BAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AACF;AAtSa,QACwB,kBACjC;;;AD3FJ,IAAO,cAAQ;","names":["TimeoutError","TimeoutError","error"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/sandbox.ts","../src/messaging.ts","../src/utils.ts","../src/consts.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { Sandbox } from './sandbox'\nexport type { Context, RunCodeOpts, CreateCodeContextOpts } from './sandbox'\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n ChartType,\n ChartTypes,\n Chart,\n BarChart,\n BarData,\n LineChart,\n ScatterChart,\n BoxAndWhiskerChart,\n BoxAndWhiskerData,\n PieChart,\n PieData,\n SuperChart,\n PointData,\n} from './charts'\nimport { Sandbox } from './sandbox'\n\nexport default Sandbox\n","import { Sandbox as BaseSandbox, InvalidArgumentError } from 'e2b'\n\nimport {\n Result,\n Execution,\n OutputMessage,\n parseOutput,\n extractError,\n ExecutionError,\n} from './messaging'\nimport {\n formatExecutionTimeoutError,\n formatRequestTimeoutError,\n readLines,\n} from './utils'\nimport { JUPYTER_PORT, DEFAULT_TIMEOUT_MS } from './consts'\n\n/**\n * Represents a context for code execution.\n */\nexport type Context = {\n /**\n * The ID of the context.\n */\n id: string\n /**\n * The language of the context.\n */\n language: string\n /**\n * The working directory of the context.\n */\n cwd: string\n}\n\n/**\n * Options for running code.\n */\nexport interface RunCodeOpts {\n /**\n * Callback for handling stdout messages.\n */\n onStdout?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling stderr messages.\n */\n onStderr?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling the final execution result.\n */\n onResult?: (data: Result) => Promise<any> | any\n /**\n * Callback for handling the `ExecutionError` object.\n */\n onError?: (error: ExecutionError) => Promise<any> | any\n /**\n * Custom environment variables for code execution.\n *\n * @default {}\n */\n envs?: Record<string, string>\n /**\n * Timeout for the code execution in **milliseconds**.\n *\n * @default 60_000 // 60 seconds\n */\n timeoutMs?: number\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * Options for creating a code context.\n */\nexport interface CreateCodeContextOpts {\n /**\n * Working directory for the context.\n *\n * @default /home/user\n */\n cwd?: string\n /**\n * Language for the context.\n *\n * @default python\n */\n language?: string\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * E2B cloud sandbox is a secure and isolated cloud environment.\n *\n * The sandbox allows you to:\n * - Access Linux OS\n * - Create, list, and delete files and directories\n * - Run commands\n * - Run isolated code\n * - Access the internet\n *\n * Check docs [here](https://e2b.dev/docs).\n *\n * Use {@link Sandbox.create} to create a new sandbox.\n *\n * @example\n * ```ts\n * import { Sandbox } from '@e2b/code-interpreter'\n *\n * const sandbox = await Sandbox.create()\n * ```\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string =\n 'code-interpreter-v1'\n\n protected get jupyterUrl(): string {\n return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(\n JUPYTER_PORT\n )}`\n }\n\n /**\n * Run the code as Python.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: 'python'\n }\n ): Promise<Execution>\n /**\n * Run the code for the specified language.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n * If no language is specified, Python is used.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: string\n }\n ): Promise<Execution>\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code\n *\n * @returns `Execution` result object\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Context to run the code in.\n */\n context?: Context\n }\n ): Promise<Execution>\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n language?: string\n context?: Context\n }\n ): Promise<Execution> {\n if (opts?.context && opts?.language) {\n throw new InvalidArgumentError(\n 'You can provide context or language, but not both at the same time.'\n )\n }\n\n const controller = new AbortController()\n\n const requestTimeout =\n opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout\n ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n if (this.envdAccessToken) {\n headers['X-Access-Token'] = this.envdAccessToken\n }\n\n try {\n const res = await fetch(`${this.jupyterUrl}/execute`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n code,\n context_id: opts?.context?.id,\n language: opts?.language,\n env_vars: opts?.envs,\n }),\n signal: controller.signal,\n keepalive: true,\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n if (!res.body) {\n throw new Error(\n `Not response body: ${res.statusText} ${await res?.text()}`\n )\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(\n execution,\n chunk,\n opts?.onStdout,\n opts?.onStderr,\n opts?.onResult,\n opts?.onError\n )\n }\n } catch (error) {\n throw formatExecutionTimeoutError(error)\n } finally {\n clearTimeout(bodyTimer)\n }\n\n return execution\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Creates a new context to run code in.\n *\n * @param opts options for creating the context.\n *\n * @returns context object.\n */\n async createCodeContext(opts?: CreateCodeContextOpts): Promise<Context> {\n try {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n language: opts?.language,\n cwd: opts?.cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Removes a context.\n *\n * @param context context to remove.\n *\n * @returns void.\n */\n async removeCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}`, {\n method: 'DELETE',\n headers,\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * List all contexts.\n *\n * @returns list of contexts.\n */\n async listCodeContexts(): Promise<Context[]> {\n try {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'GET',\n headers,\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return await res.json()\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restart a context.\n *\n * @param context context to restart.\n *\n * @returns void.\n */\n async restartCodeContext(context: Context | string): Promise<void> {\n try {\n const id = typeof context === 'string' ? context : context.id\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (this.trafficAccessToken) {\n headers['E2B-Traffic-Access-Token'] = this.trafficAccessToken\n }\n\n const res = await fetch(`${this.jupyterUrl}/contexts/${id}/restart`, {\n method: 'POST',\n headers,\n keepalive: true,\n signal: this.connectionConfig.getSignal(\n this.connectionConfig.requestTimeoutMs\n ),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { ChartTypes } from './charts'\n\nexport async function extractError(res: Response) {\n if (res.ok) {\n return\n }\n\n switch (res.status) {\n case 502:\n return new TimeoutError(\n `${await res.text()}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`\n )\n case 404:\n return new NotFoundError(await res.text())\n default:\n return new SandboxError(`${res.status} ${res.statusText}`)\n }\n}\n\n/**\n * Represents an output message from the sandbox code execution.\n */\nexport class OutputMessage {\n constructor(\n /**\n * The output line.\n */\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds.\n */\n public readonly timestamp: number,\n /**\n * Whether the output is an error.\n */\n public readonly error: boolean\n ) {}\n\n public toString() {\n return this.line\n }\n}\n\n/**\n * Represents an error that occurred during the execution of a cell.\n * The error contains the name of the error, the value of the error, and the traceback.\n */\nexport class ExecutionError {\n constructor(\n /**\n * Name of the error.\n **/\n public name: string,\n /**\n * Value of the error.\n **/\n public value: string,\n /**\n * The raw traceback of the error.\n **/\n public traceback: string\n ) {}\n}\n\n/**\n * Represents a MIME type.\n */\nexport type MIMEType = string\n\ntype E2BData = {\n data: Record<string, unknown>\n chart: ChartTypes\n}\n\n/**\n * Dictionary that maps MIME types to their corresponding representations of the data.\n */\nexport type RawData = {\n [key: MIMEType]: string\n} & E2BData\n\n/**\n * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.\n * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics\n *\n *\n * The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented\n * as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,\n * for the actual result the representation is always present for the result, the other representations are always optional.\n */\nexport class Result {\n /**\n * Text representation of the result.\n */\n readonly text?: string\n /**\n * HTML representation of the data.\n */\n readonly html?: string\n /**\n * Markdown representation of the data.\n */\n readonly markdown?: string\n /**\n * SVG representation of the data.\n */\n readonly svg?: string\n /**\n * PNG representation of the data.\n */\n readonly png?: string\n /**\n * JPEG representation of the data.\n */\n readonly jpeg?: string\n /**\n * PDF representation of the data.\n */\n readonly pdf?: string\n /**\n * LaTeX representation of the data.\n */\n readonly latex?: string\n /**\n * JSON representation of the data.\n */\n readonly json?: string\n /**\n * JavaScript representation of the data.\n */\n readonly javascript?: string\n /**\n * Contains the data from DataFrame.\n */\n readonly data?: Record<string, unknown>\n /**\n * Contains the chart data.\n */\n readonly chart?: ChartTypes\n /**\n * Extra data that can be included. Not part of the standard types.\n */\n readonly extra?: any\n\n readonly raw: RawData\n\n constructor(\n rawData: RawData,\n public readonly isMainResult: boolean\n ) {\n const data = { ...rawData }\n delete data['type']\n delete data['is_main_result']\n\n this.text = data['text']\n this.html = data['html']\n this.markdown = data['markdown']\n this.svg = data['svg']\n this.png = data['png']\n this.jpeg = data['jpeg']\n this.pdf = data['pdf']\n this.latex = data['latex']\n this.json = data['json']\n this.javascript = data['javascript']\n this.isMainResult = isMainResult\n this.raw = data\n\n this.data = data['data']\n this.chart = data['chart']\n\n this.extra = {}\n\n for (const key of Object.keys(data)) {\n if (\n ![\n 'plain',\n 'html',\n 'markdown',\n 'svg',\n 'png',\n 'jpeg',\n 'pdf',\n 'latex',\n 'json',\n 'javascript',\n 'data',\n 'chart',\n 'extra',\n 'text',\n ].includes(key)\n ) {\n this.extra[key] = data[key]\n }\n }\n }\n\n /**\n * Returns all the formats available for the result.\n *\n * @returns Array of strings representing the formats available for the result.\n */\n formats(): string[] {\n const formats = []\n if (this.html) {\n formats.push('html')\n }\n if (this.markdown) {\n formats.push('markdown')\n }\n if (this.svg) {\n formats.push('svg')\n }\n if (this.png) {\n formats.push('png')\n }\n if (this.jpeg) {\n formats.push('jpeg')\n }\n if (this.pdf) {\n formats.push('pdf')\n }\n if (this.latex) {\n formats.push('latex')\n }\n if (this.json) {\n formats.push('json')\n }\n if (this.javascript) {\n formats.push('javascript')\n }\n if (this.data) {\n formats.push('data')\n }\n\n for (const key of Object.keys(this.extra)) {\n formats.push(key)\n }\n\n return formats\n }\n\n /**\n * Returns the serializable representation of the result.\n */\n toJSON() {\n return {\n text: this.text,\n html: this.html,\n markdown: this.markdown,\n svg: this.svg,\n png: this.png,\n jpeg: this.jpeg,\n pdf: this.pdf,\n latex: this.latex,\n json: this.json,\n javascript: this.javascript,\n ...(Object.keys(this.extra).length > 0 ? { extra: this.extra } : {}),\n }\n }\n}\n\n/**\n * Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.\n */\nexport type Logs = {\n /**\n * List of strings printed to stdout by prints, subprocesses, etc.\n */\n stdout: string[]\n /**\n * List of strings printed to stderr by prints, subprocesses, etc.\n */\n stderr: string[]\n}\n\n/**\n * Represents the result of a cell execution.\n */\nexport class Execution {\n constructor(\n /**\n * List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).\n */\n public results: Result[] = [],\n /**\n * Logs printed to stdout and stderr during execution.\n */\n public logs: Logs = { stdout: [], stderr: [] },\n /**\n * An Error object if an error occurred, null otherwise.\n */\n public error?: ExecutionError,\n /**\n * Execution count of the cell.\n */\n public executionCount?: number\n ) {}\n\n /**\n * Returns the text representation of the main result of the cell.\n */\n get text(): string | undefined {\n for (const data of this.results) {\n if (data.isMainResult) {\n return data.text\n }\n }\n }\n\n /**\n * Returns the serializable representation of the execution result.\n */\n toJSON() {\n return {\n results: this.results,\n logs: this.logs,\n error: this.error,\n }\n }\n}\n\nexport async function parseOutput(\n execution: Execution,\n line: string,\n onStdout?: (output: OutputMessage) => Promise<any> | any,\n onStderr?: (output: OutputMessage) => Promise<any> | any,\n onResult?: (data: Result) => Promise<any> | any,\n onError?: (error: ExecutionError) => Promise<any> | any\n) {\n const msg = JSON.parse(line)\n\n switch (msg.type) {\n case 'result': {\n const result = new Result(\n { ...msg, type: undefined, is_main_result: undefined },\n msg.is_main_result\n )\n execution.results.push(result)\n if (onResult) {\n await onResult(result)\n }\n break\n }\n case 'stdout':\n execution.logs.stdout.push(msg.text)\n if (onStdout) {\n await onStdout({\n error: false,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'stderr':\n execution.logs.stderr.push(msg.text)\n if (onStderr) {\n await onStderr({\n error: true,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'error':\n execution.error = new ExecutionError(msg.name, msg.value, msg.traceback)\n if (onError) {\n await onError(execution.error)\n }\n break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n","import { TimeoutError } from 'e2b'\n\nexport function formatRequestTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Request timed out — the 'requestTimeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport function formatExecutionTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError(\n \"Execution timed out — the 'timeoutMs' option can be used to increase this timeout\"\n )\n }\n\n return error\n}\n\nexport async function* readLines(stream: ReadableStream<Uint8Array>) {\n const reader = stream.getReader()\n let buffer = ''\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n\n if (value !== undefined) {\n buffer += new TextDecoder().decode(value)\n }\n\n if (done) {\n if (buffer.length > 0) {\n yield buffer\n }\n break\n }\n\n let newlineIdx = -1\n\n do {\n newlineIdx = buffer.indexOf('\\n')\n if (newlineIdx !== -1) {\n yield buffer.slice(0, newlineIdx)\n buffer = buffer.slice(newlineIdx + 1)\n }\n } while (newlineIdx !== -1)\n }\n } finally {\n reader.releaseLock()\n }\n}\n","export const DEFAULT_TIMEOUT_M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AAI,OAAO;AACT,cAAM;AAAA,MACR;AAEA,aAAO,MAAM,IAAI,KAAK;AAAA,IACxB,SAAS,OAAO;AACd,YAAM,0BAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,mBAAmB,SAA0C;AACjE,QAAI;AACF,YAAM,KAAK,OAAO,YAAY,WAAW,UAAU,QAAQ;AAC3D,YAAM,UAAkC;AAAA,QACtC,gBAAgB;AAAA,MAClB;AAEA,UAAI,KAAK,oBAAoB;AAC3B,gBAAQ,0BAA0B,IAAI,KAAK;AAAA,MAC7C;AAEA,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK,UAAU,aAAa,EAAE,YAAY;AAAA,QACnE,QAAQ;AAAA,QACR;AAAA,QACA,WAAW;AAAA,QACX,QAAQ,KAAK,iBAAiB;AAAA,UAC5B,KAAK,iBAAiB;AAAA,QACxB;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,aAAa,GAAG;AACpC,UAAI,OAAO;AACT,cAAM;AAAA,MACR;AAAA,IACF,SAAS,OAAO;AACd,YAAM,0BAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AACF;AA9Ta,QACwB,kBACjC;;;AD3FJ,IAAO,cAAQ;","names":["TimeoutError","TimeoutError","error"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2b/code-interpreter",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "E2B Code Interpreter - Stateful code execution",
5
5
  "homepage": "https://e2b.dev",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "defaults"
59
59
  ],
60
60
  "dependencies": {
61
- "e2b": "^2.7.0"
61
+ "e2b": "^2.8.3"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "tsc --noEmit && tsup",