Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add docs examples for cloning repo
Vasek Mlejnsky3a7ce15226ee
diff --git a/apps/docs/src/app/agents/clone-repo/page.mdx b/apps/docs/src/app/agents/clone-repo/page.mdxnew file mode 100644index 000000000..30a0ec4a0--- /dev/null+++ b/apps/docs/src/app/agents/clone-repo/page.mdx@@ -0,0 +1,10 @@+export const metadata = {+ title: 'E2B Documentation - Cloud for AI Agents Apps',+ description: 'AI Agents - Clone Repo',+}++# Clone GitHuB Repository+Every AI Playgrounds comes in with a preinstalled `git`.+This makes it easy to clone any repository from GitHub (and even run it) and let your agent work inside repo.++<CodeGroupAutoload path="agents/clone_repo" isRunnable={true} />\ No newline at end of filediff --git a/apps/docs/src/code/js/agents/clone_repo.js b/apps/docs/src/code/js/agents/clone_repo.jsnew file mode 100644index 000000000..fc0f01609--- /dev/null+++ b/apps/docs/src/code/js/agents/clone_repo.js@@ -0,0 +1,33 @@+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 a process that will clone a repository+let proc = await session.process.start({ // $HighlightLine+ cmd: 'git clone https://github.com/cruip/open-react-template.git /code/open-react-template', // $HighlightLine+ 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++// Optional: 4. List the cntent of cloned repo+const content = await session.filesystem.list('/code/open-react-template')+console.log(content)++// Optional: 5. Install deps+console.log('Installing deps...')+proc = await session.process.start({+ cmd: 'npm install',+ rootdir: '/code/open-react-template',+ onStdout: data => console.log(data.line),+ onStderr: data => console.log(data.line),+})+await proc.finished++await session.close()diff --git a/apps/docs/src/code/js/run_all.js b/apps/docs/src/code/js/run_all.jsindex 1b3353ed5..0303ad2b1 100644--- a/apps/docs/src/code/js/run_all.js+++ b/apps/docs/src/code/js/run_all.js@@ -19,5 +19,6 @@ 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'+import * as agents_clone_repo from './agents/clone_repo.js'console.log('Done')diff --git a/apps/docs/src/code/python/_run_all.py b/apps/docs/src/code/python/_run_all.pyindex 660f8dcd7..ec76dfb15 100644--- a/apps/docs/src/code/python/_run_all.py+++ b/apps/docs/src/code/python/_run_all.py@@ -19,5 +19,6 @@ from timeout.timeout_filesystem import main as timeout_filesystem_mainfrom processes.background_processes import main as background_processes_mainfrom agents.code_exec import main as code_exec_main+from agents.clone_repo import main as clone_repo_mainprint("Done")\ No newline at end of filediff --git a/apps/docs/src/code/python/agents/clone_repo.py b/apps/docs/src/code/python/agents/clone_repo.pynew file mode 100644index 000000000..0e12bb459--- /dev/null+++ b/apps/docs/src/code/python/agents/clone_repo.py@@ -0,0 +1,44 @@+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 a process that will clone a repository+ proc = await session.process.start( # $HighlightLine+ cmd="git clone https://github.com/cruip/open-react-template.git /code/open-react-template", # $HighlightLine+ on_stdout=print_out, # $HighlightLine+ on_stderr=print_out, # $HighlightLine+ ) # $HighlightLine+ # 3. Wait for the process to finish+ await proc++ # Optional: 4. List the cntent of cloned repo+ content = await session.filesystem.list('/code/open-react-template')+ print(content)++ # Optional: 5. Install deps+ print("Installing deps...")+ proc = await session.process.start(+ cmd="npm install",+ on_stdout=print_out,+ on_stderr=print_out,+ rootdir="/code/open-react-template"+ )++ await proc++ await session.close()++asyncio.run(main())\ No newline at end of filediff --git a/apps/docs/src/code/python/agents/code_exec.py b/apps/docs/src/code/python/agents/code_exec.pyindex bc957ab1f..4b13c4d0a 100644--- a/apps/docs/src/code/python/agents/code_exec.py+++ b/apps/docs/src/code/python/agents/code_exec.py@@ -36,7 +36,7 @@ async def main():) # $HighlightLine# 4. Wait for the process to finish- await proc.finished+ await proc# 5. Or you can access output after the process has finishedoutput = proc.outputdiff --git a/apps/docs/src/components/Navigation.tsx b/apps/docs/src/components/Navigation.tsxindex 39e3239ae..b7948f5b4 100644--- a/apps/docs/src/components/Navigation.tsx+++ b/apps/docs/src/components/Navigation.tsx@@ -251,11 +251,11 @@ export const navigation = [],},{- title: 'AI Agents Use Cases',+ title: 'AI Agents Use Case',links: [{ title: 'Execute Code', href: '/agents/exec' },// { title: 'Install Packages', href: '/agents/pkg' },- // { title: 'Clone GitHub Repository', href: '/agents/clone-repo' },+ { 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' },