Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add code execution example to docs

Vasek Mlejnskye2eff273edeb
diff --git a/apps/docs/src/app/agents/exec/page.mdx b/apps/docs/src/app/agents/exec/page.mdx
new file mode 100644
index 000000000..056ee383e
--- /dev/null
+++ b/apps/docs/src/app/agents/exec/page.mdx
@@ -0,0 +1,10 @@
+export const metadata = {
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
+ description: 'AI Agents - Execute Code',
+}
+
+# Execute Code
+AI Playgrounds are great for executing any code produced by an LLM.
+This makes it a great fit for AI agents that work with code - like GitHub Copilot, for example.
+
+<CodeGroupAutoload path="agents/code_exec" isRunnable={true} />
\ No newline at end of file
diff --git a/apps/docs/src/app/getting-started/basics/page.mdx b/apps/docs/src/app/getting-started/basics/page.mdx
index f3d0c6c9d..77f19010c 100644
--- a/apps/docs/src/app/getting-started/basics/page.mdx
+++ b/apps/docs/src/app/getting-started/basics/page.mdx
@@ -1,6 +1,6 @@
export const metadata = {
- title: 'E2B Documentation',
- description: 'SDK Usage',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
+ description: 'E2B SDK Usage',
}
{/* I think this stopped working work after adding Nextjs rewrites */}
diff --git a/apps/docs/src/app/getting-started/installation/page.mdx b/apps/docs/src/app/getting-started/installation/page.mdx
index 941d8ca0c..7d0a3f151 100644
--- a/apps/docs/src/app/getting-started/installation/page.mdx
+++ b/apps/docs/src/app/getting-started/installation/page.mdx
@@ -1,5 +1,5 @@
export const metadata = {
- title: 'E2B Documentation',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
description: 'SDK Installation',
}
diff --git a/apps/docs/src/app/getting-started/sdk-logging/page.mdx b/apps/docs/src/app/getting-started/sdk-logging/page.mdx
index 95eba6391..b3b7fd159 100644
--- a/apps/docs/src/app/getting-started/sdk-logging/page.mdx
+++ b/apps/docs/src/app/getting-started/sdk-logging/page.mdx
@@ -1,5 +1,5 @@
export const metadata = {
- title: 'E2B Documentation',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
description: 'SDK Logging',
}
diff --git a/apps/docs/src/app/getting-started/sdk-multiple-processes/page.mdx b/apps/docs/src/app/getting-started/sdk-multiple-processes/page.mdx
index b0dc60e1f..57aa0d287 100644
--- a/apps/docs/src/app/getting-started/sdk-multiple-processes/page.mdx
+++ b/apps/docs/src/app/getting-started/sdk-multiple-processes/page.mdx
@@ -1,5 +1,5 @@
export const metadata = {
- title: 'E2B Documentation',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
description: 'SDK Multiple Processes',
}
diff --git a/apps/docs/src/app/getting-started/sdk-timeouts/page.mdx b/apps/docs/src/app/getting-started/sdk-timeouts/page.mdx
index 87b971950..b2b6ad4c5 100644
--- a/apps/docs/src/app/getting-started/sdk-timeouts/page.mdx
+++ b/apps/docs/src/app/getting-started/sdk-timeouts/page.mdx
@@ -1,5 +1,5 @@
export const metadata = {
- title: 'E2B Documentation',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
description: 'SDK Timeouts',
}
diff --git a/apps/docs/src/app/how-it-works/page.mdx b/apps/docs/src/app/how-it-works/page.mdx
index d33d4515b..0f6f8ed6b 100644
--- a/apps/docs/src/app/how-it-works/page.mdx
+++ b/apps/docs/src/app/how-it-works/page.mdx
@@ -1,8 +1,8 @@
export const metadata = {
- title: 'E2B Documentation',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
description:
- 'How E2B Works',
+ 'Sandboxed cloud environments for AI agents & apps with a single line of code',
}
# How E2B Works
diff --git a/apps/docs/src/app/page.mdx b/apps/docs/src/app/page.mdx
index d102ffa4a..295bdd785 100644
--- a/apps/docs/src/app/page.mdx
+++ b/apps/docs/src/app/page.mdx
@@ -5,9 +5,9 @@ import { Button } from '@/components/Button'
import { ButtonLoginToken } from '@/components/ButtonLoginToken';
export const metadata = {
- title: 'E2B Documentation',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
description:
- 'E2B - Sandboxed Cloud Environments for AI Agents',
+ 'Sandboxed cloud environments for AI agents & apps with a single line of code',
}
export const sections = [
@@ -19,9 +19,9 @@ export const sections = [
# What is E2B?
-**E2B is a cloud operating system for AI agents.**{{ className: 'lead' }}
+**E2B is cloud for AI agents and AI apps.**{{ className: 'lead' }}
-With a single line of our SDK, you can give your AI agent a sandboxed cloud environment where your agent can do any of the following (and more):
+With E2B, you can create AI playgrounds. In these AI playgrounds, you can let your AI agents and apps:
- Run any code and terminal command in a sandboxed environment
- Install dependencies and programs
- Use filesystem
@@ -43,7 +43,7 @@ Our SDK works with any AI agent (no matter what framework you're using), and wit
## Quickstart Example
<CodeGroup isRunnable={false}>
-
+
```bash {{ language: 'js' }}
npm i @e2b/sdk
```
diff --git a/apps/docs/src/app/playgrounds/limitations/page.mdx b/apps/docs/src/app/playgrounds/limitations/page.mdx
index 81d7a33d3..c5000a225 100644
--- a/apps/docs/src/app/playgrounds/limitations/page.mdx
+++ b/apps/docs/src/app/playgrounds/limitations/page.mdx
@@ -1,3 +1,9 @@
+export const metadata = {
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
+ description: 'AI PLaygrounds Limiations',
+}
+
+
# AI Playground Limitations
export const sections = [
diff --git a/apps/docs/src/app/playgrounds/overview/page.mdx b/apps/docs/src/app/playgrounds/overview/page.mdx
index 2f0a9903c..b0b55b860 100644
--- a/apps/docs/src/app/playgrounds/overview/page.mdx
+++ b/apps/docs/src/app/playgrounds/overview/page.mdx
@@ -1,6 +1,7 @@
export const metadata = {
- title: 'E2B Documentation - AI Playgrounds',
- description: 'AI Playgrounds for your agents and AI apps',
+ title: 'E2B Documentation - Cloud for AI Agents Apps',
+ description:
+ 'Sandboxed cloud environments for AI agents & apps with a single line of code',
}
# AI Playgrounds
diff --git a/apps/docs/src/code/js/agents/code_exec.js b/apps/docs/src/code/js/agents/code_exec.js
new file mode 100644
index 000000000..320c3af55
--- /dev/null
+++ b/apps/docs/src/code/js/agents/code_exec.js
@@ -0,0 +1,36 @@
+import { Session } from '@e2b/sdk'
+
+// 1. Start the playground session
+const session = await Session.create({
+ // Select the right runtime
+ // 'Node', 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'
+ id: 'Nodejs',
+ apiKey: process.env.E2B_API_KEY,
+})
+
+// 2. Save the JavaScript code to a file inside the playground
+const code = `
+ const fs = require('fs');
+ const dirContent = fs.readdirSync('/');
+ dirContent.forEach((item) => {
+ console.log('Root dir item inside playground:', item);
+ });
+`
+await session.filesystem.write('/code/index.js', code)
+
+
+// 3. Start the execution of the JavaScript file we saved
+const proc = await session.process.start({ // $HighlightLine
+ cmd: 'node /code/index.js', // $HighlightLine
+ // 4. Stream stdout, stderr
+ onStdout: (data) => console.log(data.line), // $HighlightLine
+ onStderr: (data) => console.log(data.line), // $HighlightLine
+}) // $HighlightLine
+
+// 4. Wait for the process to finish
+await proc.finished
+
+// 5. Or you can access output after the process has finished
+const output = proc.output
+
+await session.close()
diff --git a/apps/docs/src/code/js/run_all.js b/apps/docs/src/code/js/run_all.js
index 0c64557e0..1b3353ed5 100644
--- a/apps/docs/src/code/js/run_all.js
+++ b/apps/docs/src/code/js/run_all.js
@@ -18,4 +18,6 @@ import * as timeout_process from './timeout/timeout_process.js'
import * as timeout_filesystem from './timeout/timeout_filesystem.js'
import * as background_processes from './processes/background_processes.js'
+import * as agents_code_exec from './agents/code_exec.js'
+
console.log('Done')
diff --git a/apps/docs/src/code/python/_run_all.py b/apps/docs/src/code/python/_run_all.py
index 69b2d4e8a..660f8dcd7 100644
--- a/apps/docs/src/code/python/_run_all.py
+++ b/apps/docs/src/code/python/_run_all.py
@@ -18,5 +18,6 @@ from timeout.timeout_process import main as timeout_process_main
from timeout.timeout_filesystem import main as timeout_filesystem_main
from processes.background_processes import main as background_processes_main
+from agents.code_exec import main as code_exec_main
print("Done")
\ No newline at end of file
diff --git a/apps/docs/src/code/python/agents/__init__.py b/apps/docs/src/code/python/agents/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/apps/docs/src/code/python/agents/code_exec.py b/apps/docs/src/code/python/agents/code_exec.py
new file mode 100644
index 000000000..bc957ab1f
--- /dev/null
+++ b/apps/docs/src/code/python/agents/code_exec.py
@@ -0,0 +1,46 @@
+import asyncio
+from os import getenv
+from e2b import Session
+
+E2B_API_KEY = getenv("E2B_API_KEY")
+
+def print_out(output):
+ print(output.line)
+
+async def main():
+ # 1. Start the playground session
+ session = await Session.create(
+ # Select the right runtime
+ # 'Node', 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'
+ id="Nodejs",
+ api_key=E2B_API_KEY,
+ )
+
+ # 2. Save the JavaScript code to a file inside the playground
+ code = """
+ const fs = require('fs');
+ const dirContent = fs.readdirSync('/');
+ dirContent.forEach((item) => {
+ console.log('Root dir item inside playground:', item);
+ });
+ """
+ await session.filesystem.write('/code/index.js', code)
+
+
+ # 3. Start the execution of the JavaScript file we saved
+ proc = await session.process.start( # $HighlightLine
+ cmd="node /code/index.js", # $HighlightLine
+ # 4. Stream stdout, stderr
+ on_stdout=print_out, # $HighlightLine
+ on_stderr=print_out, # $HighlightLine
+ ) # $HighlightLine
+
+ # 4. Wait for the process to finish
+ await proc.finished
+
+ # 5. Or you can access output after the process has finished
+ output = proc.output
+
+ await session.close()
+
+asyncio.run(main())
\ No newline at end of file
diff --git a/apps/docs/src/components/Navigation.tsx b/apps/docs/src/components/Navigation.tsx
index 07a02d807..39e3239ae 100644
--- a/apps/docs/src/components/Navigation.tsx
+++ b/apps/docs/src/components/Navigation.tsx
@@ -250,6 +250,17 @@ export const navigation = [
{ title: 'SDK Multiple Processes', href: '/getting-started/sdk-multiple-processes' },
],
},
+ {
+ title: 'AI Agents Use Cases',
+ links: [
+ { title: 'Execute Code', href: '/agents/exec' },
+ // { title: 'Install Packages', href: '/agents/pkg' },
+ // { title: 'Clone GitHub Repository', href: '/agents/clone-repo' },
+ // { title: 'Start Process', href: '/agents/process' },
+ // { title: 'Read File', href: '/agents/read' },
+ // { title: 'Write File', href: '/agents/write' },
+ ]
+ },
{
title: 'AI Playgrounds',
links: [