Code Interpreter SDK Beta - Language Runtimes
This guide shows how to run AI-generated code in different language runtimes using the new Code Interpreter beta SDK. The following language runtimes are currently supported:
- Python
- JavaScript
- Java
- Bash
- R
1. Install the Code Interpreter beta SDK
The latest beta versions you should install can be found in NPM/PyPi release history:
- JavaScript & TypeScript
- Latest release with rc tag for
@e2b/code-interpreter
- Latest release with rc tag for
- Python
- Latest release with PRE-RELEASE for
e2b-code-interpreter
- Latest release with PRE-RELEASE for
2. Active kernel for the desired language
Each of the supported language runtimes has its own kernel.
Python
from e2b_code_interpreter import CodeInterpreter
sandbox = CodeInterpreter()
# 1. Set JS kernel - available kernel names: 'r', 'javascript', 'java', 'bash'
js_id = sandbox.notebook.create_kernel(kernel_name="javascript")
# 2. Run JS code inside code interpreter!
execution = sandbox.notebook.exec_cell("console.log('Hello World!')", kernel_id=js_id)
print(execution)
# 3. Use Python again
sandbox.notebook.exec_cell("print('Hello World!')")
JavaScript / TypeScript
import { CodeInterpreter } from '@e2b/code-interpreter'
const sandbox = await CodeInterpreter.create()
// 1. Set JS kernel - available kernel names: 'r', 'javascript', 'java', 'bash'
const jsID = await sandbox.notebook.createKernel({ kernelName: 'javascript' })
// 2. Run JS code inside code interpreter!
const execution = await sandbox.notebook.execCell("console.log('Hello World!')", { kernelID: jsID })
console.log(execution)
// 3. Use Python again
await sandbox.notebook.execCell('print("Hello World!")')