Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Improve docs

Jakub Novak1c301a79edac
diff --git a/apps/docs/src/app/code-interpreter/examples/page.mdx b/apps/docs/src/app/code-interpreter/examples/page.mdx
index c9c36bb84..95c1615e8 100644
--- a/apps/docs/src/app/code-interpreter/examples/page.mdx
+++ b/apps/docs/src/app/code-interpreter/examples/page.mdx
@@ -11,10 +11,10 @@ The following example demonstrates how to create a shared context between multip
import { CodeInterpreter } from '@e2b/code-interpreter'
const sandbox = await CodeInterpreter.create()
-await sandbox.execPython('x = 1')
+await sandbox.notebook.execCell('x = 1')
-const result = await sandbox.execPython('x += 1; x')
-console.log(result.output) // outputs 2
+const execution = await sandbox.notebook.execCell('x+=1; x')
+console.log(execution.text) // outputs 2
await sandbox.close()
```
@@ -22,10 +22,10 @@ await sandbox.close()
from e2b_code_interpreter import CodeInterpreter
with CodeInterpreter() as sandbox:
- sandbox.exec_cell("x = 1")
+ sandbox.notebook.exec_cell("x = 1")
- result = sandbox.exec_cell("x+=1; x")
- print(result.result) # outputs 2
+ execution = sandbox.notebook.exec_cell("x+=1; x")
+ print(execution.text) # outputs 2
```
</CodeGroup>
@@ -34,9 +34,9 @@ with CodeInterpreter() as sandbox:
<CodeGroup isRunnable={false}>
```js
-import { CodeInterpreter } from '@e2b/code-interpreter';
+import { CodeInterpreter } from '@e2b/code-interpreter'
-const sandbox = await CodeInterpreter.create();
+const sandbox = await CodeInterpreter.create()
const code = `
import matplotlib.pyplot as plt
@@ -50,14 +50,14 @@ plt.show()
`;
// you can install dependencies in "jupyter notebook style"
-await sandbox.execPython("!pip install matplotlib");
+await sandbox.notebook.execCell("!pip install matplotlib")
-const result = await sandbox.execPython(code);
+const execution = await sandbox.notebook.execCell(code)
// this contains the image data, you can e.g. save it to file or send to frontend
-result.display_data[0]["image/png"];
+execution.results[0].png
-await sandbox.close();
+await sandbox.close()
```
```python
import base64
@@ -80,13 +80,13 @@ plt.show()
with CodeInterpreter() as sandbox:
# you can install dependencies in "jupyter notebook style"
- sandbox.exec_cell("!pip install matplotlib")
+ sandbox.notebook.exec_cell("!pip install matplotlib")
# plot random graph
- result = sandbox.exec_cell(code)
+ execution = sandbox.notebook.exec_cell(code)
# there's your image
-image = result.display_data[0]["image/png"]
+image = execution.results[0].png
# example how to show the image / prove it works
i = base64.b64decode(image)
@@ -106,31 +106,39 @@ import { CodeInterpreter } from "@e2b/code-interpreter";
code = `
import time
+import pandas as pd
print("hello")
-time.sleep(5)
+time.sleep(3)
+data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
+display(data.head(10))
+time.sleep(3)
print("world")
-`;
+`
-const sandbox = await CodeInterpreter.create();
+const sandbox = await CodeInterpreter.create()
-await sandbox.execPython(
- code,
- (out) => console.log(out),
- (outErr) => console.error(outErr),
-);
+await sandbox.notebook.execCell(code, {
+ onStdout: (out) => console.log(out),
+ onStderr: (outErr) => console.error(outErr),
+ onResult: (result) => console.log(result.text)
+})
````
```python
from e2b_code_interpreter import CodeInterpreter
code = """
import time
+import pandas as pd
print("hello")
-time.sleep(5)
+time.sleep(3)
+data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
+display(data.head(10))
+time.sleep(3)
print("world")
"""
with CodeInterpreter() as sandbox:
- sandbox.exec_cell(code, on_stdout=print, on_stderr=print)
+ sandbox.notebook.exec_cell(code, on_stdout=print, on_stderr=print, on_result=(lambda result: print(result.text)))
```
</ CodeGroup>
diff --git a/apps/docs/src/app/code-interpreter/kernels/page.mdx b/apps/docs/src/app/code-interpreter/kernels/page.mdx
new file mode 100644
index 000000000..3671c28ba
--- /dev/null
+++ b/apps/docs/src/app/code-interpreter/kernels/page.mdx
@@ -0,0 +1,27 @@
+import Link from 'next/link'
+
+# Kernels
+
+In this section you can find information about kernels and how to use them in Code Interpreter SDK
+
+By default the template starts with one default kernel. This kernel is used to execute code, if you don't specify `kernelID`. You can imagine kernel as a separate environment where code is executed. You can have multiple kernels running at the same time. Each kernel has its own state, so you can have multiple kernels running different code at the same time.
+
+Kernel will be kept kept alive with the sandbox even if you disconnect.
+
+## Creating a new kernel
+
+To create a new kernel there's a `create kernel` method in `CodeInterpreter` class. This method takes two optional arguments:
+- `cwd` - working directory for the kernel, all system commands and file operations will be executed in this directory
+- `kernel name` - kernel spec name (defaults to default kernel spec for server). In our case it's `python3`. If you want to use another kernel, you have to install in the template first. In that case you probably want to use <Link href='code-interpreter/template'>Custom Template</Link>.
+
+## Restarting a kernel
+
+To restart a kernel you can use `restart` method. This method takes one argument - `kernelID`, if not specifed it will restart the default kernel. This method will restart the kernel and clear its state.
+
+## Listing kernels
+
+To list all kernels you can use `list` method. This method returns an array of all running kernels with their IDs and kernel spec names.
+
+## Shutting down a kernel
+
+To shutdown a kernel you can use `shutdown` method. This method takes one argument - `kernelID`, if not specifed it will delete the default kernel. This method will delete the kernel and all its state.
diff --git a/apps/docs/src/app/code-interpreter/template/page.mdx b/apps/docs/src/app/code-interpreter/template/page.mdx
index fa708be28..92a45582e 100644
--- a/apps/docs/src/app/code-interpreter/template/page.mdx
+++ b/apps/docs/src/app/code-interpreter/template/page.mdx
@@ -1,11 +1,14 @@
+import Link from 'next/link'
+import { FileCode } from 'lucide-react'
+
# Custom template using Code Interpreter
-##
-The template requires custom setup. If you want to build your own custom template and use Code Interpreter, you need to do:
+The Code Interpreter requires a template with a specific setup. If you want to build your own custom template and use Code Interpreter, you need to follow the instructions below.
+Here's all the source code for the template:
<Link
- className="w-fit flex items-center justify-start space-x-2"
+ className="w-fit flex items-center justify-start my-[-24px]"
href="https://github.com/e2b-dev/code-interpreter/blob/main/template"
rel="noopener noreferrer"
target="_blank"
@@ -14,19 +17,37 @@ The template requires custom setup. If you want to build your own custom templat
size={18}
className="text-brand-600"
/>
+ <span>
Template source code
+ </span>
</Link>
+## How to create custom template
+
+If you want to build your own custom template and use Code Interpreter, you need to do:
-Copy jupyter_server_config.py and start-up.sh from this PR
-Add following commands in your Dockerfile
+1. Copy following files to your template folder: [`jupyter_server_config.py`](https://github.com/e2b-dev/code-interpreter/blob/main/template/jupyter_server_config.py), [`ipython_kernel_config.py`](https://github.com/e2b-dev/code-interpreter/blob/main/template/ipython_kernel_config.py) and [`start-up.sh`](https://github.com/e2b-dev/code-interpreter/blob/main/template/start-up.sh).
+2. Setup jupyter server and kernel in your `Dockerfile` by adding these lines:
+```docker
# Installs jupyter server and kernel
RUN pip install jupyter-server ipykernel ipython
RUN ipython kernel install --name "python3" --user
-# Copes jupyter server config
+
+# Copies jupyter server, kernel config and start-up script
COPY ./jupyter_server_config.py /home/user/.jupyter/
-# Setups jupyter server
+COPY ./ipython_kernel_config.py /home/user/.ipython/
COPY ./start-up.sh /home/user/.jupyter/
+
+# Sets permissions for the start-up script
RUN chmod +x /home/user/.jupyter/start-up.sh
-Add the following option -c "/home/user/.jupyter/start-up.sh" to e2b template build command or add this line to your e2b.toml.
+```
+3. Add the following option `-c "/home/user/.jupyter/start-up.sh"` to `e2b template build` command or add this line to your `e2b.toml`.
+```yaml
start_cmd = "/home/user/.jupyter/start-up.sh"
+```
+
+## Install another kernels
+
+Jupyter has ability to work with different than Python kernel. It even supports multiple kernels in one notebook. If you want to install another kernels.
+
+You can find list of available kernels [here](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels). Each has a little bit different installation process, but in general you need to install kernel package and register it in jupyter.