Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add docs examples showing how to run any shell command
Vasek Mlejnskyc7c4458a07ce
diff --git a/apps/docs/src/app/agents/shell-commands/page.mdx b/apps/docs/src/app/agents/shell-commands/page.mdxnew file mode 100644index 000000000..cf6946e3c--- /dev/null+++ b/apps/docs/src/app/agents/shell-commands/page.mdx@@ -0,0 +1,10 @@+export const metadata = {+ title: 'E2B Documentation - Cloud for AI Agents Apps',+ description: 'AI Agents - Run Any Shell Commands',+}++# Run Any Shell Commands+AI Agents can run any shell commands - that means starting any processes, installing libraries, and more.+Running a shell command is the most basic primitive that you can use to control the AI playgrounds.++<CodeGroupAutoload path="agents/start_process" isRunnable={true} />\ No newline at end of filediff --git a/apps/docs/src/code/js/agents/start_process.js b/apps/docs/src/code/js/agents/start_process.jsnew file mode 100644index 000000000..d443ba1c1--- /dev/null+++ b/apps/docs/src/code/js/agents/start_process.js@@ -0,0 +1,25 @@+import { Session } from '@e2b/sdk'++// 1. Start the playground session+const session = await Session.create({+ // 'Node', 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'+ id: 'Nodejs',+ apiKey: process.env.E2B_API_KEY,+})++// 2. Start the shell commdand+let proc = await session.process.start({ // $HighlightLine+ // Print names of all running processes+ cmd: "ps aux | tr -s ' ' | cut -d ' ' -f 11", // $HighlightLine+ // Stream stdout and stderr+ onStderr: data => console.log(data.line), // $HighlightLine+ onStdout: data => console.log(data.line), // $HighlightLine+}) // $HighlightLine++// 3. Wait for the process to finish+await proc.finished++// 4. 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.jsindex 0303ad2b1..f1bd315fd 100644--- a/apps/docs/src/code/js/run_all.js+++ b/apps/docs/src/code/js/run_all.js@@ -20,5 +20,6 @@ import * as background_processes from './processes/background_processes.js'import * as agents_code_exec from './agents/code_exec.js'import * as agents_clone_repo from './agents/clone_repo.js'+import * as agents_start_process from './agents/start_process.js'console.log('Done')diff --git a/apps/docs/src/code/python/_run_all.py b/apps/docs/src/code/python/_run_all.pyindex ec76dfb15..d9c1dcef5 100644--- a/apps/docs/src/code/python/_run_all.py+++ b/apps/docs/src/code/python/_run_all.py@@ -20,5 +20,6 @@ from processes.background_processes import main as background_processes_mainfrom agents.code_exec import main as code_exec_mainfrom agents.clone_repo import main as clone_repo_main+from agents.start_process import main as start_process_mainprint("Done")\ No newline at end of filediff --git a/apps/docs/src/code/python/agents/start_process.py b/apps/docs/src/code/python/agents/start_process.pynew file mode 100644index 000000000..61de36fdd--- /dev/null+++ b/apps/docs/src/code/python/agents/start_process.py@@ -0,0 +1,34 @@+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+ id="Nodejs",+ api_key=E2B_API_KEY,+ )++ # 2. Start the shell commdand+ proc = await session.process.start( # $HighlightLine+ # Print names of all running processes+ cmd="ps aux | tr -s ' ' | cut -d ' ' -f 11", # $HighlightLine+ on_stdout=print_out, # $HighlightLine+ on_stderr=print_out, # $HighlightLine+ ) # $HighlightLine++ # 3. Wait for the process to finish+ await proc++ # 4. Or you can access output after the process has finished+ output = proc.output++ await session.close()++asyncio.run(main())\ No newline at end of filediff --git a/apps/docs/src/components/Navigation.tsx b/apps/docs/src/components/Navigation.tsxindex b7948f5b4..0255a680c 100644--- a/apps/docs/src/components/Navigation.tsx+++ b/apps/docs/src/components/Navigation.tsx@@ -256,9 +256,10 @@ export const navigation = [{ 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: 'Run Shell Commands', href: '/agents/shell-commands' },// { title: 'Read File', href: '/agents/read' },// { title: 'Write File', href: '/agents/write' },+ // TODO: Guide for building ffmpeg agent]},{