Skip to content

Commit 026c882

Browse files
committed
Refactor JS SDK (Renaming, remove notebook module scope, remove context managing methods)
1 parent f481c28 commit 026c882

33 files changed

+159
-273
lines changed

js/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ npm install @e2b/code-interpreter
1818
### Minimal example with the sharing context
1919

2020
```js
21-
import { CodeInterpreter } from '@e2b/code-interpreter'
21+
import { Sandbox } from '@e2b/code-interpreter'
2222

23-
const sandbox = await CodeInterpreter.create()
24-
await sandbox.notebook.execCell('x = 1')
23+
const sandbox = await Sandbox.create()
24+
await sandbox.runCode('x = 1')
2525

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

29-
await sandbox.close()
29+
await sandbox.kill()
3030
```
3131

3232
### Get charts and any display-able data
3333

3434
```js
35-
import { CodeInterpreter } from '@e2b/code-interpreter'
35+
import { Sandbox } from '@e2b/code-interpreter'
3636

37-
const sandbox = await CodeInterpreter.create()
37+
const sandbox = await Sandbox.create()
3838

3939
const code = `
4040
import matplotlib.pyplot as plt
@@ -48,20 +48,20 @@ plt.show()
4848
`
4949

5050
// you can install dependencies in "jupyter notebook style"
51-
await sandbox.notebook.execCell('!pip install matplotlib')
51+
await sandbox.runCode('!pip install matplotlib')
5252

53-
const execution = await sandbox.notebook.execCell(code)
53+
const execution = await sandbox.runCode(code)
5454

5555
// this contains the image data, you can e.g. save it to file or send to frontend
5656
execution.results[0].png
5757

58-
await sandbox.close()
58+
await sandbox.kill()
5959
```
6060

6161
### Streaming code output
6262

6363
```js
64-
import { CodeInterpreter } from '@e2b/code-interpreter'
64+
import { Sandbox } from '@e2b/code-interpreter'
6565

6666
const code = `
6767
import time
@@ -75,13 +75,13 @@ time.sleep(3)
7575
print("world")
7676
`
7777

78-
const sandbox = await CodeInterpreter.create()
78+
const sandbox = await Sandbox.create()
7979

80-
await sandbox.notebook.execCell(code, {
80+
await sandbox.runCode(code, {
8181
onStdout: (out) => console.log(out),
8282
onStderr: (outErr) => console.error(outErr),
8383
onResult: (result) => console.log(result.text),
8484
})
8585

86-
await sandbox.close()
86+
await sandbox.kill()
8787
```

js/example.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dotenv from 'dotenv'
22

3-
import { CodeInterpreter } from './dist'
3+
import { Sandbox } from './dist'
44

55
dotenv.config()
66

@@ -22,10 +22,10 @@ import pandas
2222
pandas.DataFrame({"a": [1, 2, 3]})
2323
`
2424

25-
const sandbox = await CodeInterpreter.create()
25+
const sandbox = await Sandbox.create()
2626
console.log(sandbox.sandboxId)
2727

28-
const execution = await sandbox.notebook.execCell(code, {
28+
const execution = await sandbox.runCode(code, {
2929
onStdout(msg) {
3030
console.log('stdout', msg)
3131
},

js/src/consts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const DEFAULT_TIMEOUT_MS = 60_000 // 1 minute
2+
export const JUPYTER_PORT = 49999

js/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from 'e2b'
22

3-
export { Sandbox, JupyterExtension } from './sandbox'
4-
3+
export { Sandbox } from './sandbox'
4+
export type { Context } from './sandbox'
55
export type {
66
Logs,
77
ExecutionError,

0 commit comments

Comments
 (0)