Skip to content

Commit ddf7f28

Browse files
committed
2 parents 12ec3bc + f47d9e6 commit ddf7f28

File tree

22 files changed

+126
-255
lines changed

22 files changed

+126
-255
lines changed

.changeset/four-yaks-know.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/js_tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ jobs:
5454
uses: oven-sh/setup-bun@v2
5555
with:
5656
version: 1.1.x
57-
#
58-
# - name: Run Bun tests
59-
# run: pnpm test:bun
60-
# env:
61-
# E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
57+
58+
- name: Run Bun tests
59+
run: pnpm test:bun
60+
env:
61+
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
6262

6363
- name: Install Deno
6464
uses: denoland/setup-deno@v1

.github/workflows/python_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ jobs:
4040
run: poetry build
4141

4242
- name: Run tests
43-
run: poetry run pytest -n 4 --verbose -x
43+
run: poetry run pytest --verbose -x
4444
env:
4545
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999

100100
release:
101101
needs: [python-tests, js-tests]
102-
if: always() && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true'
102+
if: (!cancelled()) && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true'
103103
name: Release
104104
runs-on: ubuntu-latest
105105
steps:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img width="100" src="https://github.com/e2b-dev/E2B/blob/main/readme-assets/logo-circle.png" alt="e2b logo">
2+
<img width="100" src="https://raw.githubusercontent.com/e2b-dev/E2B/refs/heads/main/readme-assets/logo-circle.png" alt="e2b logo">
33
</p>
44

55
<h4 align="center">

js/README.md

Lines changed: 26 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,50 @@
11
<p align="center">
2-
<img width="100" src="/readme-assets/logo-circle.png" alt="e2b logo">
2+
<img width="100" src="https://raw.githubusercontent.com/e2b-dev/E2B/refs/heads/main/readme-assets/logo-circle.png" alt="e2b logo">
33
</p>
44

5-
6-
<h1 align="center">
7-
Code interpreter extension for JavaScript
8-
</h1>
9-
10-
<h4 align="center">
11-
<a href="https://pypi.org/project/e2b/">
12-
<img alt="Last 1 month downloads for the Python SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
13-
style="color:transparent;width:auto;height:100%" src="https://img.shields.io/pypi/dm/e2b?label=PyPI%20Downloads">
14-
</a>
5+
<h4 align="center">
156
<a href="https://www.npmjs.com/package/e2b">
16-
<img alt="Last 1 month downloads for the Python SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
7+
<img alt="Last 1 month downloads for the JavaScript SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
178
style="color:transparent;width:auto;height:100%" src="https://img.shields.io/npm/dm/e2b?label=NPM%20Downloads">
189
</a>
1910
</h4>
2011

12+
<!---
13+
<img width="100%" src="/readme-assets/preview.png" alt="Cover image">
14+
--->
15+
## What is E2B?
16+
[E2B](https://www.e2b.dev/) is an open-source infrastructure that allows you run to AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our [JavaScript SDK](https://www.npmjs.com/package/@e2b/code-interpreter) or [Python SDK](https://pypi.org/project/e2b_code_interpreter).
2117

22-
The repository contains a template and modules for the code interpreter sandbox. It is based on the Jupyter server and implements the Jupyter Kernel messaging protocol. This allows for sharing context between code executions and improves support for plotting charts and other display-able data.
23-
24-
## Key Features
25-
26-
- **Stateful Execution**: Unlike traditional sandboxes that treat each code execution independently, this package maintains context across executions.
27-
- **Displaying Charts & Data**: Implements parts of the [Jupyter Kernel messaging protocol](https://jupyter-client.readthedocs.io/en/latest/messaging.html), which support for interactive features like plotting charts, rendering DataFrames, etc.
18+
## Run your first Sandbox
2819

29-
## Installation
20+
### 1. Install SDK
3021

31-
```sh
32-
npm install @e2b/code-interpreter
3322
```
34-
35-
## Examples
36-
37-
### Minimal example with the sharing context
38-
39-
```js
40-
import { Sandbox } from '@e2b/code-interpreter'
41-
42-
const sandbox = await Sandbox.create()
43-
await sbx.runCode()('x = 1')
44-
45-
const execution = await sbx.runCode()('x+=1; x')
46-
console.log(execution.text) // outputs 2
47-
48-
await sandbox.close()
23+
npm i @e2b/code-interpreter
4924
```
5025

51-
### Get charts and any display-able data
52-
53-
```js
54-
import { Sandbox } from '@e2b/code-interpreter'
55-
56-
const sandbox = await Sandbox.create()
57-
58-
const code = `
59-
import matplotlib.pyplot as plt
60-
import numpy as np
61-
62-
x = np.linspace(0, 20, 100)
63-
y = np.sin(x)
64-
65-
plt.plot(x, y)
66-
plt.show()
67-
`
68-
69-
// you can install dependencies in "jupyter notebook style"
70-
await sandbox.runCode('!pip install matplotlib')
71-
72-
const execution = await sandbox.runCode(code)
73-
74-
// this contains the image data, you can e.g. save it to file or send to frontend
75-
execution.results[0].png
76-
77-
await sandbox.kill()
26+
### 2. Get your E2B API key
27+
1. Sign up to E2B [here](https://e2b.dev).
28+
2. Get your API key [here](https://e2b.dev/dashboard?tab=keys).
29+
3. Set environment variable with your API key.
7830
```
31+
E2B_API_KEY=e2b_***
32+
```
7933

80-
### Streaming code output
34+
### 3. Execute code with code interpreter inside Sandbox
8135

82-
```js
36+
```ts
8337
import { Sandbox } from '@e2b/code-interpreter'
8438

85-
const code = `
86-
import time
87-
import pandas as pd
88-
89-
print("hello")
90-
time.sleep(3)
91-
data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
92-
display(data.head(10))
93-
time.sleep(3)
94-
print("world")
95-
`
96-
9739
const sandbox = await Sandbox.create()
40+
await sbx.runCode('x = 1')
9841

99-
await sandbox.runCode(code, {
100-
onStdout: (out) => console.log(out),
101-
onStderr: (outErr) => console.error(outErr),
102-
onResult: (result) => console.log(result.text),
103-
})
104-
105-
await sandbox.kill()
42+
const execution = await sbx.runCode('x+=1; x')
43+
console.log(execution.text) // outputs 2
10644
```
10745

108-
### More resources
109-
- Check out the [JavaScript/TypeScript](https://e2b.dev/docs/hello-world/js) and [Python](https://e2b.dev/docs/hello-world/py) "Hello World" guides to learn how to use our SDK.
110-
111-
- See [E2B documentation](https://e2b.dev/docs) to get started.
112-
113-
- Visit our [Cookbook](https://github.com/e2b-dev/e2b-cookbook/tree/main) to get inspired by examples with different LLMs and AI frameworks.
114-
115-
116-
___
46+
### 4. Check docs
47+
Visit [E2B documentation](https://e2b.dev/docs).
11748

118-
<div align='center'>
119-
<!-- <a href="https://e2b.dev/docs" target="_blank">
120-
<img src="https://img.shields.io/badge/docs-%2300acee.svg?color=143D52&style=for-the-badge&logo=x&logoColor=white" alt=docs style="margin-bottom: 5px;"/></a> -->
121-
<a href="https://twitter.com/e2b_dev" target="_blank">
122-
<img src="https://img.shields.io/badge/x (twitter)-%2300acee.svg?color=000000&style=for-the-badge&logo=x&logoColor=white" alt=linkedin style="margin-bottom: 5px;"/></a>
123-
<a href="https://discord.com/invite/U7KEcGErtQ" target="_blank">
124-
<img src="https://img.shields.io/badge/discord -%2300acee.svg?color=143D52&style=for-the-badge&logo=discord&logoColor=white" alt=discord style="margin-bottom: 5px;"/></a>
125-
<a href="https://www.linkedin.com/company/e2b-dev/" target="_blank">
126-
<img src="https://img.shields.io/badge/linkedin-%2300acee.svg?color=000000&style=for-the-badge&logo=linkedin&logoColor=white" alt=linkedin style="margin-bottom: 5px;"/></a>
127-
</div align='center'>
49+
### 5. E2B cookbook
50+
Visit our [Cookbook](https://github.com/e2b-dev/e2b-cookbook/tree/main) to get inspired by examples with different LLMs and AI frameworks.

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@e2b/code-interpreter",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"description": "E2B Code Interpreter - Stateful code execution",
55
"homepage": "https://e2b.dev",
66
"license": "MIT",

js/src/charts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export type BoxAndWhiskerData = {
9595
median: number
9696
third_quartile: number
9797
max: number
98+
outliers: number[]
9899
}
99100

100101
export type BoxAndWhiskerChart = Chart2D & {

js/src/messaging.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ export class Result {
183183
'json',
184184
'javascript',
185185
'data',
186+
'chart',
186187
'extra',
188+
"text"
187189
].includes(key)
188190
) {
189191
this.extra[key] = data[key]

js/tests/charts/boxAndWhisker.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ data = {
1717
# Create figure and axis
1818
fig, ax = plt.subplots(figsize=(10, 6))
1919
20-
# Plot box plot
21-
ax.boxplot(data.values(), labels=data.keys())
22-
2320
# Customize plot
2421
ax.set_title('Exam Scores Distribution')
2522
ax.set_xlabel('Class')
@@ -52,12 +49,11 @@ plt.show()
5249
const bars = chart.elements
5350
expect(bars.length).toBe(3)
5451

55-
bars.forEach((bar: any) => {
56-
expect(typeof bar.min).toBe('number')
57-
expect(typeof bar.first_quartile).toBe('number')
58-
expect(typeof bar.median).toBe('number')
59-
expect(typeof bar.third_quartile).toBe('number')
60-
expect(typeof bar.max).toBe('number')
61-
expect(typeof bar.label).toBe('string')
62-
})
52+
expect(bars.map((bar) => bar.label)).toEqual(['Class A', 'Class B', 'Class C'])
53+
expect(bars.map((bar) => bar.outliers)).toEqual([[], [76], []])
54+
expect(bars.map((bar) => bar.min)).toEqual([78, 84, 75])
55+
expect(bars.map((bar) => bar.first_quartile)).toEqual([85, 84.75, 79])
56+
expect(bars.map((bar) => bar.median)).toEqual([88, 88, 82])
57+
expect(bars.map((bar) => bar.third_quartile)).toEqual([90, 90.5, 86])
58+
expect(bars.map((bar) => bar.max)).toEqual([92, 95, 88])
6359
})

0 commit comments

Comments
 (0)