Skip to content

Commit d35f82a

Browse files
mishushakovmlejva
andauthored
Updated docs on JS/TS kernel (#748)
- Added TypeScript to the JavaScript doc - Updated the example showing top-level await, esm-style module imports and promise resolution --------- Co-authored-by: Vasek Mlejnsky <vasek@e2b.dev>
1 parent 4ffb211 commit d35f82a

3 files changed

Lines changed: 66 additions & 10 deletions

File tree

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,75 @@
1-
# Run JavaScript code
2-
Use the `runCode`/`run_code` method to run JavaScript code inside the sandbox.
3-
You'll need to pass the `language` parameter with value `javascript` or `js`.
1+
# Run JavaScript and TypeScript code
2+
3+
Use the `runCode`/`run_code` method to run JavaScript and TypeScript code inside the sandbox.
4+
You'll need to pass the `language` parameter with value `javascript` or `js` for JavaScript and `typescript` or `ts` for TypeScript.
5+
6+
<Note>
7+
The E2B Code Interpreter supports TypeScript, top-level await, ESM-style imports and automatic promises resolution.
8+
</Note>
9+
410
<CodeGroup>
511
```js
6-
import { Sandbox } from '@e2b/code-interpreter'
12+
import { Sandbox } from "@e2b/code-interpreter";
13+
14+
// Create a new sandbox
15+
const sbx = await Sandbox.create();
16+
17+
// Install the axios package
18+
await sbx.commands.run("npm install axios");
19+
20+
// Run the code
21+
const execution = await sbx.runCode(`
22+
import axios from "axios";
23+
24+
const url: string = "https://api.github.com/status";
25+
const response = await axios.get(url);
26+
response.data;
27+
`,
28+
{ language: "ts" }
29+
);
730

8-
const sbx = await Sandbox.create()
9-
const execution = await sbx.runCode('console.log("Hello, world!")', { language: 'js' })
10-
console.log(execution)
31+
console.log(execution);
32+
33+
// Execution {
34+
// results: [],
35+
// logs: {
36+
// stdout: [ "{ message: 'GitHub lives! (2025-05-28 10:49:55 -0700) (1)' }\n" ],
37+
// stderr: [],
38+
// },
39+
// error: undefined,
40+
// executionCount: 1,
41+
// text: [Getter],
42+
// toJSON: [Function: toJSON],
43+
// }
1144
```
1245
```python
1346
from e2b_code_interpreter import Sandbox
1447

48+
# Create a new sandbox
1549
sbx = Sandbox()
16-
execution = sbx.run_code('console.log("Hello, world!")', language="js")
50+
51+
# Install the axios package
52+
sbx.commands.run("npm install axios")
53+
54+
# Run the code
55+
execution = sbx.run_code("""
56+
import axios from "axios";
57+
58+
const url: string = "https://api.github.com/status";
59+
const response = await axios.get(url);
60+
response.data;
61+
""",
62+
language="ts",
63+
)
64+
1765
print(execution)
66+
67+
# Execution(
68+
# Results: [
69+
# Result({ message: 'GitHub lives! (2025-05-28 10:48:47 -0700) (1)' })
70+
# ],
71+
# Logs: Logs(stdout: [], stderr: []),
72+
# Error: None
73+
# )
1874
```
1975
</CodeGroup>

apps/web/src/app/(docs)/docs/code-interpreting/supported-languages/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Typically you use Python to run AI-generated code for data analysis but you can
44

55
Out of the box E2B Sandbox supports:
66
- [Python](/docs/code-interpreting/supported-languages/python)
7-
- [JavaScript](/docs/code-interpreting/supported-languages/javascript)
7+
- [JavaScript and TypeScript](/docs/code-interpreting/supported-languages/javascript)
88
- [R](/docs/code-interpreting/supported-languages/r)
99
- [Java](/docs/code-interpreting/supported-languages/java)
1010
- [Bash](/docs/code-interpreting/supported-languages/bash)

apps/web/src/components/Navigation/routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const docRoutes: NavGroup[] = [
187187
href: '/docs/code-interpreting/supported-languages/python',
188188
},
189189
{
190-
title: 'JavaScript',
190+
title: 'JavaScript and TypeScript',
191191
href: '/docs/code-interpreting/supported-languages/javascript',
192192
},
193193
{

0 commit comments

Comments
 (0)