Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Update docs

Vasek Mlejnsky0ab63b3688b8
diff --git a/apps/web/src/app/(docs)/docs/code-interpreting/analyze-data-with-ai/preinstalled-libraries/page.mdx b/apps/web/src/app/(docs)/docs/code-interpreting/analyze-data-with-ai/pre-installed-libraries/page.mdx
similarity index 100%
rename from apps/web/src/app/(docs)/docs/code-interpreting/analyze-data-with-ai/preinstalled-libraries/page.mdx
rename to apps/web/src/app/(docs)/docs/code-interpreting/analyze-data-with-ai/pre-installed-libraries/page.mdx
diff --git a/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdx b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdx
new file mode 100644
index 000000000..e48ed001c
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdx
@@ -0,0 +1,164 @@
+# Interactive plots
+
+E2B also allows you to create interactive charts with custom styling.
+
+E2B automatically detects charts when executing Python code with `runCode()` in JavaScript or `run_code()` in Python. The Python code must include Matplotlib charts.
+
+When a chart is deteted, E2B sends the data of the chart back to the client. You can access the chart in the `execution.results` array where each item is a `Result` object with the `graph` property.
+
+Here's a simple example of bar chart:
+<CodeGroup>
+```js
+import { Sandbox, BarGraph } from '@e2b/code-interpreter'
+
+const code = `
+import matplotlib.pyplot as plt
+
+# Prepare data
+authors = ['Author A', 'Author B', 'Author C', 'Author D']
+sales = [100, 200, 300, 400]
+
+# Create and customize the bar graph
+plt.figure(figsize=(10, 6))
+plt.bar(authors, sales, label='Books Sold', color='blue')
+plt.xlabel('Authors')
+plt.ylabel('Number of Books Sold')
+plt.title('Book Sales by Authors')
+
+# Display the graph
+plt.tight_layout()
+plt.show()
+`
+
+const sandbox = await Sandbox.create()
+const result = await sandbox.runCode(code)
+const graph = result.results[0].graph as BarGraph
+
+console.log('Type:', graph.type)
+console.log('Title:', graph.title)
+console.log('X Label:', graph.x_label)
+console.log('Y Label:', graph.y_label)
+console.log('X Unit:', graph.x_unit)
+console.log('Y Unit:', graph.y_unit)
+console.log('Elements:', graph.elements)
+```
+```python
+from e2b_code_interpreter import Sandbox
+
+code = """
+import matplotlib.pyplot as plt
+
+# Prepare data
+authors = ['Author A', 'Author B', 'Author C', 'Author D']
+sales = [100, 200, 300, 400]
+
+# Create and customize the bar graph
+plt.figure(figsize=(10, 6))
+plt.bar(authors, sales, label='Books Sold', color='blue')
+plt.xlabel('Authors')
+plt.ylabel('Number of Books Sold')
+plt.title('Book Sales by Authors')
+
+# Display the graph
+plt.tight_layout()
+plt.show()
+"""
+
+sandbox = Sandbox()
+execution = sandbox.run_code(code)
+graph = execution.results[0].graph
+
+print('Type:', graph.type)
+print('Title:', graph.title)
+print('X Label:', graph.x_label)
+print('Y Label:', graph.y_label)
+print('X Unit:', graph.x_unit)
+print('Y Unit:', graph.y_unit)
+print('Elements:')
+for element in graph.elements:
+ print('\n Label:', element.label)
+ print(' Value:', element.value)
+ print(' Group:', element.group)
+```
+</CodeGroup>
+
+
+The code above will output the following:
+<CodeGroup isTerminalCommand>
+```bash {{ language: 'js' }}
+Type: bar
+Title: Book Sales by Authors
+X Label: Authors
+Y Label: Number of Books Sold
+X Unit: null
+Y Unit: null
+Elements: [
+ {
+ label: "Author A",
+ group: "Books Sold",
+ value: 100,
+ }, {
+ label: "Author B",
+ group: "Books Sold",
+ value: 200,
+ }, {
+ label: "Author C",
+ group: "Books Sold",
+ value: 300,
+ }, {
+ label: "Author D",
+ group: "Books Sold",
+ value: 400,
+ }
+]
+```
+```bash {{ language: 'python' }}
+Type: GraphType.BAR
+Title: Book Sales by Authors
+X Label: Authors
+Y Label: Number of Books Sold
+X Unit: None
+Y Unit: None
+Elements:
+
+ Label: Author A
+ Value: 100.0
+ Group: Books Sold
+
+ Label: Author B
+ Value: 200.0
+ Group: Books Sold
+
+ Label: Author C
+ Value: 300.0
+ Group: Books Sold
+
+ Label: Author D
+ Value: 400.0
+ Group: Books Sold
+```
+</CodeGroup>
+
+You can then use this data to create an interactive chart with your favorite charting library on frontend.
+
+---
+
+## Supported intertactive charts
+
+The following charts are currently supported:
+- [Line chart](#line-chart)
+- [Bar chart](#bar-chart)
+- [Scatter plot](#scatter-plot)
+- [Pie chart](#pie-chart)
+- [Box and whisker plot](#box-and-whisker-plot)
+
+
+## Line chart
+
+## Bar chart
+
+## Scatter plot
+
+## Pie chart
+
+## Box and whisker plot
\ No newline at end of file
diff --git a/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/page.mdx b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/page.mdx
new file mode 100644
index 000000000..3300192dd
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/page.mdx
@@ -0,0 +1,9 @@
+# Create charts & visualizations
+E2B Sandbox allows you to create charts and visualizations by executing Python code inside the sandbox with `runCode()` method in JavaScript and `run_code()` method in Python.
+
+These charts and visualizations can be [static](/docs/code-interpreting/create-charts-visualizations/static-charts) or [interactive](/docs/code-interpreting/create-charts-visualizations/interactive-charts) plots.
+
+<Note>
+Learn more about different types of results that E2B Sandbox can return [(TODO: link)here](/docs/code-interpreting/results).
+</Note>
+
diff --git a/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/static-charts/page.mdx b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/static-charts/page.mdx
new file mode 100644
index 000000000..e3f0cc4e5
--- /dev/null
+++ b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/static-charts/page.mdx
@@ -0,0 +1,74 @@
+import Image from 'next/image'
+import imgStaticChart from '@/images/static-chart.png'
+
+# Static charts
+
+Every time you run Python code with `runCode()` in JavaScript or `run_code()` method in Python, the code is executed in a headless Jupyter server inside the sandbox.
+
+E2B automatically detects any plots created with Matplotlib and sends them back to the client as images encoded in the base64 format.
+These images are directly accesible on the [(todo: link to reference)`result`](/todo) items in the [(todo: link to reference)`execution.results` array](/todo).
+
+Here's how to retrieve a static chart from the executed Python code that contains a Matplotlib plot.
+<CodeGroup>
+```js
+import { Sandbox } from '@e2b/code-interpreter'
+import fs from 'fs'
+
+const codeToRun = `
+import matplotlib.pyplot as plt
+
+plt.plot([1, 2, 3, 4])
+plt.ylabel('some numbers')
+plt.show()
+`
+const sandbox = await Sandbox.create()
+
+// Run the code inside the sandbox
+const execution = await sandbox.runCode(codeToRun)
+
+ // There's only one result in this case - the plot displayed with `plt.show()`
+const firstResult = execution.results[0]
+
+if (firstResult.png) {
+ // Save the png to a file. The png is in base64 format.
+ fs.writeFileSync('chart.png', firstResult.png, { encoding: 'base64' })
+ console.log('Chart saved as chart.png')
+}
+```
+```python
+import base64
+from e2b_code_interpreter import Sandbox
+
+sbx = Sandbox()
+
+code_to_run = """
+import matplotlib.pyplot as plt
+
+plt.plot([1, 2, 3, 4])
+plt.ylabel('some numbers')
+plt.show()
+"""
+
+sandbox = Sandbox()
+
+# Run the code inside the sandbox
+execution = sandbox.run_code(code_to_run)
+
+# There's only one result in this case - the plot displayed with `plt.show()`
+first_result = execution.results[0]
+
+if first_result.png:
+ # Save the png to a file. The png is in base64 format.
+ with open('chart.png', 'wb') as f:
+ f.write(base64.b64decode(first_result.png))
+ print('Chart saved as chart.png')
+```
+</CodeGroup>
+
+The code in the variable `codeToRun`/`code_to_run` will produce this following plot that we're saving as `chart.png` file.
+<Image
+ src={imgStaticChart}
+ className="rounded w-full"
+ alt="Static chart produced by the code"
+ unoptimized
+/>
\ No newline at end of file
diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsx
index 092acbbff..53a51def6 100644
--- a/apps/web/src/components/Navigation/routes.tsx
+++ b/apps/web/src/components/Navigation/routes.tsx
@@ -159,8 +159,22 @@ export const routes: NavGroup[] = [
],
},
{
- title: '* Create charts & visualizations',
+ title: '* Charts & visualizations',
href: '/docs/code-interpreting/create-charts-visualizations',
+ links: [
+ {
+ title: 'Overview',
+ href: '/docs/code-interpreting/create-charts-visualizations',
+ },
+ {
+ title: 'Static charts',
+ href: '/docs/code-interpreting/create-charts-visualizations/static-charts',
+ },
+ {
+ title: 'Interactive charts',
+ href: '/docs/code-interpreting/create-charts-visualizations/interactive-charts',
+ },
+ ]
},
{
title: '* Connect your data',
@@ -281,24 +295,24 @@ export const routes: NavGroup[] = [
title: '* Persistence',
href: '/docs/sandbox/persistence',
},
+ ],
+ },
+ {
+ title: '* Templates',
+ items: [
{
- title: '* Customization',
- links: [
- {
- title: '* Overview',
- href: '/docs/sandbox/custom',
- },
- {
- title: '* CPU & RAM',
- href: '/docs/sandbox/custom/compute',
- },
- {
- title: '* Preinstall packages (TODO: Better title for custom sandbox templates)',
- href: '/docs/sandbox/custom/sandbox-template',
- },
- ]
+ title: '* Sandbox customization',
+ href: '/docs/sandbox/custom',
},
- ],
+ {
+ title: '* Customize CPU & RAM',
+ href: '/docs/sandbox/custom/compute',
+ },
+ {
+ title: '* Preinstall packages (TODO: Better title for custom sandbox templates)',
+ href: '/docs/sandbox/custom/sandbox-template',
+ },
+ ]
},
{
title: '* Filesystem',
@@ -351,6 +365,19 @@ export const routes: NavGroup[] = [
},
]
},
+ {
+ title: '* Latency',
+ items: [
+ {
+ title: '* Start times',
+ href: '/docs/latency/start-times',
+ },
+ {
+ title: '* Sandbox operations',
+ href: '/docs/latency/sandbox-operations',
+ },
+ ]
+ },
{
title: '* CLI',
items: [
diff --git a/apps/web/src/images/static-chart.png b/apps/web/src/images/static-chart.png
new file mode 100644
index 000000000..2b27ad430
Binary files /dev/null and b/apps/web/src/images/static-chart.png differ