Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Update custom sandbox guide
Vasek Mlejnsky200775ec0fe1
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex fecf0b8a8..6ebc1645d 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -79,4 +79,4 @@// "python.analysis.inlayHints.variableTypes": true,// "python.analysis.autoImportCompletions": true,// "python.analysis.completeFunctionParens": true-}\ No newline at end of file+}diff --git a/apps/docs/src/app/guide/custom-sandbox/page.mdx b/apps/docs/src/app/guide/custom-sandbox/page.mdxindex 9c5d29c70..37229072d 100644--- a/apps/docs/src/app/guide/custom-sandbox/page.mdx+++ b/apps/docs/src/app/guide/custom-sandbox/page.mdx@@ -2,11 +2,7 @@ import Image from 'next/image'# Creating Custom Sandbox-In this guide, we'll create a custom E2B sandbox.----with preinstalled dependencies and files.+In this guide, we'll create a custom E2B sandbox with preinstalled dependencies and files.Once the sandbox is built, we'll show how to spawn and control it with our SDK.## Prerequisites@@ -15,122 +11,175 @@ Once the sandbox is built, we'll show how to spawn and control it with our SDK.## 1. Install E2B CLI+<CodeGroup isTerminalCommand title="Install CLI" isRunnable={false}>```bashnpm install -g @e2b/cli@latest```+</CodeGroup><Note>You need Node.js 18.0.0 or later to install the CLI.</Note>-## 2. CLI login+## 2. Login to CLIBefore you create your first custom sandbox, you will need to authenticate in the CLI with your E2B account.Run the following command in your terminal.+<CodeGroup isTerminalCommand title="Login to CLI" isRunnable={false}>```bashe2b login```+</CodeGroup>++<Note>+You need to have an existing E2B account to login. Sign up [here](/getting-started/api-key).+</Note>-## 3. Create sandbox template file-To describe how your custom sandbox will look like, you create a new Dockerfile and name it `e2b.Dockerfile`.-We use this Dockerfile as the [sandbox template file](/sandbox/templates/template-file).+## 3. Create `e2b.Dockerfile`+To describe how your custom sandbox will look like, create a new Dockerfile and name it `e2b.Dockerfile`.+We use this Dockerfile as the [template file](/sandbox/templates/template-file).<Note>-Run `e2b init` to create a basic `e2b.Dockerfile` in the current directory.+Run `e2b init` to create `e2b.Dockerfile` in the current directory.</Note>-We want to have ffmpeg installed in our custom sandbox, so we'll create the `e2b.Dockerfile` with the following content.+We want our custom sandbox to have the [ffmpeg](https://www.ffmpeg.org/) isntalled - ffmpeg is a tool for editing video and audio files.++<CodeGroup isFileName title="e2b.Dockerfile" isRunnable={false}>```bash# You can use most of the Debian-based base imagesFROM ubuntu:22.04-# Install dependencies and customize sandbox+# Install the ffmpeg tool/RUN apt update \- && apt install -y sudo \- && sudo apt install -y ffmpeg+ && apt install -y ffmpeg```+</CodeGroup>## 4. Build custom sandboxNow it's time to create your custom sandbox based on the sandbox template file (the `e2b.Dockefile` file) you just created in the previous step.Run the following command inside the template file directory in your terminal.+<CodeGroup isTerminalCommand title="Build sandbox template" isRunnable={false}>```bash-e2b build+e2b build --name "my-agent-sandbox"```+</CodeGroup><Note>Use the `.dockerignore` file to exclude files from the sandbox template.</Note>The final output should look similar to this.++<CodeGroup title="Build output" isRunnable={false}>```bash-Preparing sandbox template building (113 files in Docker build context).+Preparing sandbox template building (1 files in Docker build context).Found ./e2b.Dockerfile that will be used to build the sandbox template.-Started building the sandbox template 3y5bvra6kgq0kaumgztu--Step 1/4 : FROM ubuntu:22.04- ---> e4c58958181a-Step 2/4 : RUN apt update && apt install sudo- ---> Using cache- ---> 4762cc0db1ff-Step 3/4 : RUN type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)- ---> Using cache- ---> 384706ddfe2f-Step 4/4 : RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null sudo apt update sudo apt install gh -y- ---> Using cache- ---> b8649b84c829+Started building the sandbox template my-agent-sandbox++# Truncated for visibility+# ...+# ...+Successfully built b8649b84c829-Successfully tagged us-central1-docker.pkg.dev/e2b-prod/custom-environments/3y5bvra6kgq0kaumgztu:b96935dc-fe87-45fb-229d-a3fba4fe160d+Successfully tagged us-central1-docker.pkg.dev/e2b-prod/custom-environments/1wdqsf9le9gk21ztb4mo:b3a31d32-fc01-164f-be9c-0b4ba5ac8f3cRunning postprocessing. It can take up to few minutes.-✅ Building sandbox template 3y5bvra6kgq0kaumgztu finished.+Running postprocessing. It can take up to few minutes.++✅ Building sandbox template my-agent-sandbox finished.++ Now you can start creating your sandboxes from this template. You can find more here:+ https://e2b.dev/docs/guide/custom-sandbox, section Spawn and control your sandbox.++ | Python SDK |+ ==============+ from e2b import Sandbox++ # Start sandbox+ sandbox = Sandbox(id="my-agent-sandbox")++ # Interact with sandbox. Learn more here:+ # https://e2b.dev/docs/sandbox/overview++ # Close sandbox once done+ sandbox.close()++ | JS SDK |+ ==========+ import { Sandbox } from '@e2b/sdk'++ // Start sandbox+ const sandbox = await Sandbox.create({ id: 'my-agent-sandbox' })++ // Interact with sandbox. Learn more here:+ // https://e2b.dev/docs/sandbox/overview++ // Close sandbox once done+ await sandbox.close()++Created config ./e2b.toml```+</CodeGroup>This will create the `e2b.toml` file storing the sandbox config.+<CodeGroup isFileName title="e2b.toml" isRunnable={false}>```toml# This is a config for E2B sandbox template-id = "3y5bvra6kgq0kaumgztu"+id = "1wdqsf9le9gk21ztb4mo"dockerfile = "e2b.Dockerfile"+name = "my-agent-sandbox"```+</CodeGroup>-**Our custom sandbox ID is `3y5bvra6kgq0kaumgztu` in this case.**+| Sandbox template name | Sandbox template ID |+---|---|+|`e2b.Dockerfile`|`1wdqsf9le9gk21ztb4mo`|### Updating your sandboxIf you want to update your sandbox, you run the same command you did to build it.This will rebuild the image and update your sandbox template.You don't need to specify the `--dockerfile` flag again.+<CodeGroup isTerminalCommand title="Update sandbox template" isRunnable={false}>```bashe2b build```+</CodeGroup>## 5. Spawn and control your sandbox-Now you can use the [E2B SDK](/getting-started/installation) to control your new custom sandbox.+Now you can use the [E2B SDK](/getting-started/installation) to spawn & control your new custom sandbox.-Our custom sandbox ID is `3y5bvra6kgq0kaumgztu` from the previous step. We'll just pass it to the SDK.+The sandbox template name is `my-agent-sandbox`. We'll use it as an unique identifier and pass it to the SDK as the `id` parameter.+This way, we'll be able to spawn our custom sandbox and control it with the SDK.-<CodeGroup isRunnable={false}>+<CodeGroup title="Spawn & control your custom sandbox" isRunnable={true}>```js {{ language: 'js' }}import { Sandbox } from '@e2b/sdk'-const sandboxID = '3y5bvra6kgq0kaumgztu'+// Spawn your custom sandbox+const sandbox = await Sandbox.create({ id: 'my-agent-sandbox' }) // $HighlightLine-const sandbox = await Sandbox.create({- id: sandboxID,-})+// Interact with sandbox. Learn more here:+// https://e2b.dev/docs/sandbox/overview+// Close sandbox once doneawait sandbox.close()``````python {{ language: 'python' }}from e2b import Sandbox-sandbox_id = '3y5bvra6kgq0kaumgztu'+# Spawn your custom sandbox+sandbox = Sandbox(id="my-agent-sandbox") # $HighlightLine-sandbox = Sandbox(id=sandbox_id)+# Interact with sandbox. Learn more here:+# https://e2b.dev/docs/sandbox/overview+# Close sandbox once donesandbox.close()```</CodeGroup>diff --git a/apps/docs/src/components/Code.tsx b/apps/docs/src/components/Code.tsxindex 4931ee09c..02c8ea242 100644--- a/apps/docs/src/components/Code.tsx+++ b/apps/docs/src/components/Code.tsx@@ -4,7 +4,12 @@ import { Children, createContext, isValidElement, useContext, useEffect, useReduimport { Tab } from '@headlessui/react'import clsx from 'clsx'import { create } from 'zustand'-import { LoaderIcon, PlayIcon, File } from 'lucide-react'+import {+ LoaderIcon,+ PlayIcon,+ File,+ Terminal,+} from 'lucide-react'import { CopyButton } from '@/components/CopyButton'import { useApiKey } from '@/utils/useUser'@@ -27,7 +32,7 @@ export function getPanelTitle({return title}if (language && language in languageNames) {- return languageNames[language]+ return languageNames[language]}return 'Code'}@@ -201,7 +206,7 @@ function CodePanel({</pre></div>)}- <CopyButton code={code}/>+ <CopyButton code={code} /></div>)}@@ -210,35 +215,62 @@ export function CodeGroupHeader({title,children,selectedIndex,- isFileName = false,+ isFileName,+ isTerminalCommand,}: {title: string;children: React.ReactNode;selectedIndex: number;- isFileName: boolean;+ isFileName?: boolean;+ isTerminalCommand?: boolean;}) {const hasTabs = Children.count(children) > 1- if (!title && !hasTabs) return null+ if (!title && !hasTabs && !isTerminalCommand) return nullreturn (<divclassName="flex min-h-[calc(theme(spacing.12)+1px)] flex-wrap items-center justify-between gap-x-4 border-b border-zinc-700 bg-zinc-800 px-4 dark:border-zinc-800 dark:bg-transparent"><div className="flex flex-col items-start">{title && (- <div className="pl-2 mt-3">+ <div>{isFileName ? (<div className="flex items-center justify-start space-x-2"><File+ className="text-brand-300"size={18}strokeWidth={1}/>- <h3 className="text-sm text-brand-400 font-mono">{title}</h3>+ <h3 className="text-sm text-gray-500 font-mono">{title}</h3></div>- ) : (- <h3 className="text-sm text-gray-500 text-brand-400">{title}</h3>+ ) : isTerminalCommand ? (+ <div className="flex items-center justify-start space-x-2">+ <Terminal+ className="text-brand-300"+ size={18}+ strokeWidth={1}+ />+ {title && (+ <h3 className="text-sm text-gray-500">{title}</h3>+ )}+ </div>+ ) : (+ <h3 className="pt-2 text-sm text-gray-500 text-brand-400">{title}</h3>)}</div>)}++ {isTerminalCommand && !title && (+ <div className="flex items-center justify-start space-x-2">+ <Terminal+ className="text-brand-300"+ size={18}+ strokeWidth={1}+ />+ </div>+ )}+++{hasTabs && (<Tab.List className="-mb-px flex gap-4 text-xs font-medium">{Children.map(children, (child, childIndex) => (@@ -290,9 +322,9 @@ export function CodeGroupHeader({}function CodeGroupPanels({- children,- ...props- }: React.ComponentPropsWithoutRef<typeof CodePanel>) {+ children,+ ...props+}: React.ComponentPropsWithoutRef<typeof CodePanel>) {const hasTabs = Children.count(children) > 1/* <INTERNAL> */@@ -427,11 +459,13 @@ function useOutputReducer() {export function CodeGroup({children,title,+ isTerminalCommand,isFileName,path,...props}: React.ComponentPropsWithoutRef<typeof CodeGroupPanels> & {title?: string;+ isTerminalCommand?: boolean;isFileName?: boolean;path?: string; // For analytics}) {@@ -449,6 +483,7 @@ export function CodeGroup({title={title}selectedIndex={tabGroupProps.selectedIndex}isFileName={isFileName}+ isTerminalCommand={isTerminalCommand}>{children}</CodeGroupHeader>@@ -477,9 +512,9 @@ export function CodeGroup({}export function Code({- children,- ...props- }: React.ComponentPropsWithoutRef<'code'>) {+ children,+ ...props+}: React.ComponentPropsWithoutRef<'code'>) {/* <DYNAMIC-API-REPLACEMENT> */// let apiKey = useApiKey()// if (children.replace && apiKey) children = children.replace(`{{API_KEY}}`, `${apiKey}`)@@ -493,16 +528,16 @@ export function Code({'`Code` children must be a string when nested inside a `CodeGroup`.',)}- return <code {...props} dangerouslySetInnerHTML={{ __html: children }}/>+ return <code {...props} dangerouslySetInnerHTML={{ __html: children }} />}return <code {...props}>{children}</code>}export function Pre({- children,- ...props- }: React.ComponentPropsWithoutRef<typeof CodeGroup>) {+ children,+ ...props+}: React.ComponentPropsWithoutRef<typeof CodeGroup>) {const isGrouped = useContext(CodeGroupContext)if (isGrouped) {diff --git a/apps/docs/src/components/Navigation/routes.tsx b/apps/docs/src/components/Navigation/routes.tsxindex 90fd3c329..b00e1afb6 100644--- a/apps/docs/src/components/Navigation/routes.tsx+++ b/apps/docs/src/components/Navigation/routes.tsx@@ -269,13 +269,4 @@ export const routes = [},],},- // {- // title: 'E2B CLI',- // links: [- // {- // title: 'Overview',- // href: '/cli/overview',- // },- // ],- // },]