Step 1: Install Code Interpreter SDK

Step 1: Install Code Interpreter SDK

JavaScript / TypeScript

npm
npm

Python

Step 2: Execute AI-generated code

Step 2: Execute AI-generated code

JavaScript / TypeScript

import { CodeInterpreter } from '@e2b/code-interpreter'

const sandbox = await CodeInterpreter.create()
await sandbox.notebook.execCell('x = 1')

const execution = await sandbox.notebook.execCell('x+=1; x')
console.log(execution.text)  // outputs 2

await sandbox.close()
import { 
  CodeInterpreter,
} from '@e2b/code-interpreter'

const sandbox = await CodeInterpreter.create()
await sandbox.notebook.execCell('x = 1')

const execution = await sandbox
.notebook
.execCell('x+=1; x')

console.log(execution.text)  // outputs 2

await sandbox.close()

Python

from e2b_code_interpreter import CodeInterpreter

with CodeInterpreter() as sandbox:
    sandbox.notebook.exec_cell("x = 1")

    execution = sandbox.notebook.exec_cell("x+=1; x")
    print(execution.text)  # outputs 2
from e2b_code_interpreter import CodeInterpreter

with CodeInterpreter() as sandbox:
  sandbox.notebook.exec_cell("x = 1")

  execution = sandbox.notebook.exec_cell("x+=1; x")
  print(execution.text)  # outputs 2