Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Update docs
Vasek Mlejnskyb6bb93eb105d
diff --git a/apps/web/src/app/(docs)/docs/code-interpreting/streaming/page.mdx b/apps/web/src/app/(docs)/docs/code-interpreting/streaming/page.mdxnew file mode 100644index 000000000..bb6ec8cbb--- /dev/null+++ b/apps/web/src/app/(docs)/docs/code-interpreting/streaming/page.mdx@@ -0,0 +1,136 @@+# Streaming++Use E2B SDK allows you to stream the output, and results when executing code in the sandbox.+++## Stream `stdout` and `stderr`+When using the `runCode()` method in JavaScript or `run_code()` in Python you can pass `onStdout`/`on_stdout` and `onStderr`/`on_stderr` callbacks to handle the output.++<CodeGroup>+```js+import { Sandbox } from '@e2b/code-interpreter'++const codeToRun = `+ import time+ import sys+ print("This goes first to stdout")+ time.sleep(3)+ print("This goes later to stderr", file=sys.stderr)+ time.sleep(3)+ print("This goes last")+`+const sandbox = await Sandbox.create()+sandbox.runCode(codeToRun, {+ onStdout: data => console.log('stdout:', data), // $HighlightLine+ onStderr: data => console.error('stderr:', data), // $HighlightLine+})+```+```python+from e2b_code_interpreter import Sandbox++code_to_run = """+ import time+ import sys+ print("This goes first to stdout")+ time.sleep(3)+ print("This goes later to stderr", file=sys.stderr)+ time.sleep(3)+ print("This goes last")+"""++sandbox = Sandbox()+sandbox.run_code(+ code_to_run,+ on_stdout=lambda data: print('stdout:', data), # $HighlightLine+ on_stderr=lambda data: print('stderr:', data), # $HighlightLine+)+```+</CodeGroup>++The code above will print the following:++<CodeGroup>+```javascript {{ language: 'javascript' }}+stdout: {+ error: false,+ line: "This goes first to stdout\n",+ timestamp: 1729049666861000,+}+stderr: {+ error: true,+ line: "This goes later to stderr\n",+ timestamp: 1729049669924000,+}+stdout: {+ error: false,+ line: "This goes last\n",+ timestamp: 1729049672664000,+}+```+```bash {{ language: 'python' }}+stdout: This goes first to stdout++stderr: This goes later to stderr++stdout: This goes last++```+</CodeGroup>++## Stream `results`++When using the `runCode()` method in JavaScript or `run_code()` in Python you can pass `onResults`/`on_results` callback+to receive results from the sandbox like charts, tables, text, and more.++<CodeGroup>+```js+const codeToRun = `+import matplotlib.pyplot as plt++# Prepare data+categories = ['Category A', 'Category B', 'Category C', 'Category D']+values = [10, 20, 15, 25]++# Create and customize the bar chart+plt.figure(figsize=(10, 6))+plt.bar(categories, values, color='green')+plt.xlabel('Categories')+plt.ylabel('Values')+plt.title('Values by Category')++# Display the chart+plt.show()+`+const sandbox = await Sandbox.create()+await sandbox.runCode(codeToRun, {+ onResult: result => console.log('result:', result), // $HighlightLine+})+```+```python+from e2b_code_interpreter import Sandbox++code_to_run = """+import matplotlib.pyplot as plt++# Prepare data+categories = ['Category A', 'Category B', 'Category C', 'Category D']+values = [10, 20, 15, 25]++# Create and customize the bar chart+plt.figure(figsize=(10, 6))+plt.bar(categories, values, color='green')+plt.xlabel('Categories')+plt.ylabel('Values')+plt.title('Values by Category')++# Display the chart+plt.show()+"""++sandbox = Sandbox()+sandbox.run_code(+ code_to_run,+ on_result=lambda result: print('result:', result), # $HighlightLine+)+```+</CodeGroup>diff --git a/apps/web/src/app/(docs)/docs/page.mdx b/apps/web/src/app/(docs)/docs/page.mdxindex c3ae1dbd8..100656904 100644--- a/apps/web/src/app/(docs)/docs/page.mdx+++ b/apps/web/src/app/(docs)/docs/page.mdx@@ -12,12 +12,12 @@ import { CodeInterpreting } from '@/components/CodeInterpreting'# E2B DocumentationHere you'll find all the guides, concepts, and API reference for developing with E2B.-<CodeGroup isRunnable={false}>+<CodeGroup isTerminalCommand>```bash {{ language: 'js' }}-npm i e2b+npm i @e2b/code-interpreter``````bash {{ language: 'python' }}-pip install e2b+pip install e2b-code-interpreter```</CodeGroup>diff --git a/apps/web/src/app/(docs)/docs/sandbox-template/customize-cpu-ram/page.mdx b/apps/web/src/app/(docs)/docs/sandbox-template/customize-cpu-ram/page.mdxnew file mode 100644index 000000000..e12f095dd--- /dev/null+++ b/apps/web/src/app/(docs)/docs/sandbox-template/customize-cpu-ram/page.mdx@@ -0,0 +1,13 @@+# Customize sandbox CPU & RAM+You can customize the CPU and RAM of your sandbox template via E2B CLI.++You'll need to create a sandbox [template first](/docs/sandbox-template).++During the build step, you can specify the CPU and RAM of your sandbox template.++The following command will create a sandbox template with 2 CPUs and 2GB of RAM.+<CodeGroup isTerminalCommand>+```bash+e2b template build -c "/root/.jupyter/start-up.sh" --cpu-count 2 --memory-mb 2048+```+</CodeGroup>diff --git a/apps/web/src/app/(docs)/docs/sandbox-template/page.mdx b/apps/web/src/app/(docs)/docs/sandbox-template/page.mdxnew file mode 100644index 000000000..7a1e75ac7--- /dev/null+++ b/apps/web/src/app/(docs)/docs/sandbox-template/page.mdx@@ -0,0 +1,112 @@+# Sandbox templates++Sandbox templates allow you to customize the sandbox environment to your needs.++To create a sandbox template, you specify the `e2b.Dockerfile`. We then take this Dockerfile and create a new sandbox template from it and give you back a template ID.++You can then use this template ID to create a new sandbox with the SDK based on the template you created.++## How to create custom sandbox++**Steps**+1. [Install E2B CLI](#1-install-e2b-cli)+1. [Initialize sandbox template](#2-initialize-sandbox-template)+1. [Customize `e2b.Dockerfile`](#3-customize-e2bdockerfile)+1. [Build your sandbox template](#4-build-your-sandbox-template)+1. [Start your custom sandbox](#5-start-your-custom-sandbox)+++### 1. Install E2B CLI+Install E2B CLI with npm:+<CodeGroup isTerminalCommand>+```bash+npm i @e2b/cli+```+</CodeGroup>++### 2. Initialize sandbox template+The following command will create a basic `e2b.Dockerfile` in the current directory.++<CodeGroup isTerminalCommand>+```bash+e2b template init+```+</CodeGroup>++### 3. Customize `e2b.Dockerfile`+Now you can customize your sandbox template by editing the `e2b.Dockerfile` file.+<CodeGroup title="e2b.Dockerfile">+```bash+# Make sure to use this base image+FROM e2bdev/code-interpreter:latest # $HighlightLine++# Install some Python packages+RUN pip install cowsay # $HighlightLine+```+</CodeGroup>++### 4. Build your sandbox template+Now you can build your sandbox template. We'll use Docker and the E2B CLI.+What is going to happen is that E2B CLI will call Docker to build the image and then push it to the E2B cloud.+Then we convert the Docker image to a micro VM that can be then launched as a sandbox with our SDK.++<CodeGroup isTerminalCommand>+```bash+e2b template build -c "/root/.jupyter/start-up.sh"+```+</CodeGroup>++This process will take a moment. In the end, you'll see your template ID that you'll need to use to create a sandbox with the SDK.++### 5. Start your custom sandbox+Now you can use the template ID to create a sandbox with the SDK.++<CodeGroup>+```javascript {{ language: 'js' }}+import { sandbox } from '@e2b/code-interpreter'++// Your template ID from the previous step+const templateID = 'id-of-your-template' // $HighlightLine+// Pass the template ID to the `Sandbox.create` method+const sandbox = await Sandbox.create(templateID) // $HighlightLine++// The template installed cowsay, so we can use it+const execution = await sandbox.runCode(`+import cowsay+cowsay.say('Hello from E2B!')+`)++console.log(execution.stdout)+```+```python {{ language: 'python' }}+from e2b_code_interpreter import Sandbox++# Your template ID from the previous step+template_id = 'id-of-your-template' # $HighlightLine+# Pass the template ID to the `Sandbox.create` method+sandbox = Sandbox(template_id) # $HighlightLine++# The template installed cowsay, so we can use it+execution = sandbox.run_code("""+import cowsay+cowsay.say('Hello from E2B!')+""")++print(execution.stdout)+```+</CodeGroup>+++++++++++++++diff --git a/apps/web/src/components/Code.tsx b/apps/web/src/components/Code.tsxindex 3a19d7995..dfc6a0bb5 100644--- a/apps/web/src/components/Code.tsx+++ b/apps/web/src/components/Code.tsx@@ -96,7 +96,7 @@ export function CodeGroupHeader({selectedIndex: number;isTerminalCommand?: boolean;}) {- const hasTabs = Children.count(children) > 0+ const hasTabs = Children.count(children) > 1if (!title && !hasTabs && !isTerminalCommand) return nullreturn (@@ -178,7 +178,7 @@ function CodeGroupPanels({children,...props}: React.ComponentPropsWithoutRef<typeof CodePanel>) {- const hasTabs = Children.count(children) > 0+ const hasTabs = Children.count(children) > 1/* <INTERNAL> */// @ts-ignore@@ -302,7 +302,7 @@ export function CodeGroup({isFileName?: boolean;path?: string; // For analytics}) {- const hasTabs = Children.count(children) > 0+ const hasTabs = Children.count(children) > 1const containerClassName ='not-prose my-6 overflow-hidden rounded-2xl bg-zinc-900 shadow-md dark:ring-1 dark:ring-white/10'const languages =diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsxindex dcd049b06..b5999841d 100644--- a/apps/web/src/components/Navigation/routes.tsx+++ b/apps/web/src/components/Navigation/routes.tsx@@ -180,7 +180,7 @@ export const routes: NavGroup[] = []},{- title: '* Streaming',+ title: 'Streaming',href: '/docs/code-interpreting/streaming',},{@@ -329,19 +329,15 @@ export const routes: NavGroup[] = [],},{- title: '* Templates',+ title: 'Templates',items: [{- title: '* Sandbox customization',- href: '/docs/sandbox/custom',- },- {- title: '* Customize CPU & RAM',- href: '/docs/sandbox/custom/compute',+ title: 'Sandbox customization',+ href: '/docs/sandbox-template',},{- title: '* Preinstall packages (TODO: Better title for custom sandbox templates)',- href: '/docs/sandbox/custom/sandbox-template',+ title: 'Customize CPU & RAM',+ href: '/docs/sandbox-template/customize-cpu-ram',},]},