Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions docs/template/examples/claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
description: "Claude Code Agent available in a sandbox"
---

Run Claude Code in a sandbox to execute AI-generated code safely.

## Install Claude Code

Set up Node.js with Claude Code and the tools it needs: curl for fetching, git for repos, and ripgrep for fast code search.

Check warning on line 10 in docs/template/examples/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/claude-code.mdx#L10

Did you really mean 'repos'?

Check warning on line 10 in docs/template/examples/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/claude-code.mdx#L10

Did you really mean 'ripgrep'?

<CodeGroup>

Expand Down Expand Up @@ -33,6 +38,9 @@

</CodeGroup>

## Build and publish

Build the template. Claude Code itself is lightweight, so minimal resources work fine.

<CodeGroup>

Expand All @@ -41,7 +49,7 @@
import { Template, defaultBuildLogger } from 'e2b'
import { template as claudeCodeTemplate } from './template'

Template.build(claudeCodeTemplate, 'claude-code', {
await Template.build(claudeCodeTemplate, 'claude-code', {
cpuCount: 1,
memoryMB: 1024,
onBuildLogs: defaultBuildLogger(),
Expand All @@ -62,59 +70,47 @@

</CodeGroup>

## Run AI prompts

Create a sandbox with your Anthropic API key and pipe prompts to Claude. It can write files, run commands, and build whatever you describe. Get your API key from the [Anthropic Console](https://console.anthropic.com/).

The `-p` flag runs Claude in non-interactive pipe mode. The `--dangerously-skip-permissions` flag allows Claude to execute file and command operations without confirmation prompts—this is safe since the sandbox is isolated. Setting `timeout=0` disables the command timeout, letting Claude run as long as needed.

<CodeGroup>

```typescript JavaScript & TypeScript
// sandbox.ts
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create('claude-code', {
const sandbox = await Sandbox.create('claude-code', {
timeoutMs: 60_000,
envs: {
ANTHROPIC_API_KEY: '<your api key>',
},
})

console.log('Sandbox created', sbx.sandboxId)

// Print help for Claude Code
// const result = await sbx.commands.run('claude --help')
// console.log(result.stdout)

// Run a prompt with Claude Code
const result = await sbx.commands.run(
const result = await sandbox.commands.run(
`echo 'Create a hello world index.html' | claude -p --dangerously-skip-permissions`,
{ timeoutMs: 0 }
)

console.log(result.stdout)

sbx.kill()
```

```python Python
# sandbox.py
from e2b import Sandbox

sbx = Sandbox(
sandbox = Sandbox.create(
'claude-code',
timeout=60,
envs={
'ANTHROPIC_API_KEY': '<your api key>',
},
)
print("Sandbox created", sbx.sandbox_id)

# Print help for Claude Code
# result = sbx.commands.run('claude --help')
# print(result.stdout)

# Run a prompt with Claude Code
result = sbx.commands.run(
result = sandbox.commands.run(
"echo 'Create a hello world index.html' | claude -p --dangerously-skip-permissions",
timeout=0,
)
print(result.stdout)

sbx.kill()
```

</CodeGroup>
39 changes: 37 additions & 2 deletions docs/template/examples/desktop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
description: "Sandbox with Ubuntu Desktop and VNC access"
---

Ubuntu Desktop with XFCE, accessible via [noVNC](https://novnc.com/) on port 6080. noVNC provides browser-based access to the desktop through VNC over WebSocket—you can view and interact with the desktop directly in your browser without installing a VNC client.

## Set up the desktop environment

Install XFCE with all the essentials: file manager, text editor, LibreOffice, and more. noVNC provides browser-based access without a native VNC client.

<CodeGroup>

Expand Down Expand Up @@ -48,7 +53,7 @@
'apt-get clean',
'rm -rf /var/lib/apt/lists/*',
])
// Streaming server setup
// noVNC and websockify for browser-based VNC access
.runCmd([
'git clone --branch e2b-desktop https://github.com/e2b-dev/noVNC.git /opt/noVNC',
'ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html',
Expand Down Expand Up @@ -109,7 +114,7 @@
"rm -rf /var/lib/apt/lists/*",
]
)
# Setup NoVNC and websockify
# noVNC and websockify for browser-based VNC access
.run_cmd(
[
"git clone --branch e2b-desktop https://github.com/e2b-dev/noVNC.git /opt/noVNC",
Expand All @@ -131,6 +136,7 @@

</CodeGroup>

The startup script initializes the display server, desktop environment, and VNC stack. It starts Xvfb (a virtual framebuffer), launches the XFCE session, runs x11vnc to share the display, and starts noVNC to bridge VNC to WebSocket for browser access.

Check warning on line 139 in docs/template/examples/desktop.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/desktop.mdx#L139

Did you really mean 'Xvfb'?

Check warning on line 139 in docs/template/examples/desktop.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/desktop.mdx#L139

Did you really mean 'framebuffer'?

```bash start_command.sh
#!/bin/bash
Expand All @@ -156,6 +162,9 @@
sleep 2
```

## Build and publish

Build the template. The desktop environment needs 8 CPUs and 8GB RAM for smooth rendering, window compositing, and running desktop applications like LibreOffice.

Check warning on line 167 in docs/template/examples/desktop.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/desktop.mdx#L167

Did you really mean 'CPUs'?

<CodeGroup>

Expand Down Expand Up @@ -184,3 +193,29 @@
```

</CodeGroup>

## Connect to the desktop

Create a sandbox and open the URL in your browser. You'll see a full Ubuntu desktop running in your sandbox.

<CodeGroup>

```typescript JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('desktop', { timeoutMs: 60_000 })

const url = sandbox.getHost(6080)
console.log('Desktop available at:', url)
```

```python Python
from e2b import Sandbox

sandbox = Sandbox.create('desktop', timeout=60)

url = sandbox.get_host(6080)
print('Desktop available at:', url)
```

</CodeGroup>
52 changes: 41 additions & 11 deletions docs/template/examples/expo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
description: "Expo web app running in the sandbox using Node.js"
---

Basic Expo app.
[Expo](https://expo.dev/) app with the dev server running on port 8081. Expo is a React Native framework that simplifies mobile and web app development.

<Note>
The development server runs on port 8081 as soon as the sandbox is ready.
</Note>
## Create the Expo project

Scaffold a fresh Expo app. The dev server starts automatically when the sandbox boots.

<CodeGroup>
```typescript JavaScript & TypeScript
// template.ts
import { defaultBuildLogger, waitForURL } from "e2b";
import { Template, waitForURL } from 'e2b'

export const template = Template()
.fromNodeImage()
.setWorkdir("/home/user/expo-app")
.runCmd("npx create-expo-app@latest . --yes")
.runCmd("mv /home/user/expo-app/* /home/user/ && rm -rf /home/user/expo-app")
.setWorkdir("/home/user")
.setStartCmd("npx expo start", waitForURL("http://localhost:8081"));
.setWorkdir('/home/user/expo-app')
.runCmd('npx create-expo-app@latest . --yes')
// Move project files to /home/user for a cleaner working directory
.runCmd('mv /home/user/expo-app/* /home/user/ && rm -rf /home/user/expo-app')
.setWorkdir('/home/user')
.setStartCmd('npx expo start', waitForURL('http://localhost:8081'))
```

```python Python
Expand All @@ -32,20 +33,25 @@
.from_node_image()
.set_workdir("/home/user/expo-app")
.run_cmd("npx create-expo-app@latest . --yes")
# Move project files to /home/user for a cleaner working directory
.run_cmd("mv /home/user/expo-app/* /home/user/ && rm -rf /home/user/expo-app")
.set_workdir("/home/user")
.set_start_cmd("npx expo start", wait_for_url('http://localhost:8081'))
)
```
</CodeGroup>

## Build and publish

Build the template with enough memory for the Expo bundler.

Check warning on line 46 in docs/template/examples/expo.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/expo.mdx#L46

Did you really mean 'bundler'?

<CodeGroup>
```typescript JavaScript & TypeScript
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as expoTemplate } from './template'

Template.build(expoTemplate, 'expo-app', {
await Template.build(expoTemplate, 'expo-app', {
cpuCount: 4,
memoryMB: 8192,
onBuildLogs: defaultBuildLogger(),
Expand All @@ -64,3 +70,27 @@
)
```
</CodeGroup>

## Access the dev server

Create a sandbox and get the URL. Open it in your browser to see the Expo web preview on port 8081.

<CodeGroup>
```typescript JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('expo-app', { timeoutMs: 60_000 })

const url = sandbox.getHost(8081)
console.log('Expo app running at:', url)
```

```python Python
from e2b import Sandbox

sandbox = Sandbox.create('expo-app', timeout=60)

url = sandbox.get_host(8081)
print('Expo app running at:', url)
```
</CodeGroup>
38 changes: 35 additions & 3 deletions docs/template/examples/nextjs-bun.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
description: "Next.js web app running in the sandbox using Bun"
---

Basic Next.js app with Tailwind and shadcn UI using Bun.
Next.js app with Tailwind and [shadcn/ui](https://ui.shadcn.com/) using [Bun](https://bun.sh/), a fast JavaScript runtime and package manager. The dev server starts automatically on port 3000.

<Note>
The development server runs on port 3000 as soon as the sandbox is ready.
For an npm-based version, see [Next.js App](/docs/template/examples/nextjs).
</Note>

## Set up Next.js with Bun

Use Bun for faster installs and hot reloads. This template includes TypeScript, Tailwind, and all shadcn components.

Check warning on line 14 in docs/template/examples/nextjs-bun.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/nextjs-bun.mdx#L14

Did you really mean 'shadcn'?

<CodeGroup>
```typescript JavaScript & TypeScript
// template.ts
Expand Down Expand Up @@ -47,13 +51,17 @@
```
</CodeGroup>

## Build and publish

Build the template. Bun makes the initial setup noticeably faster than npm.

<CodeGroup>
```typescript JavaScript & TypeScript
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as nextJSTemplate } from './template'

Template.build(nextJSTemplate, 'nextjs-app-bun', {
await Template.build(nextJSTemplate, 'nextjs-app-bun', {
cpuCount: 4,
memoryMB: 4096,
onBuildLogs: defaultBuildLogger(),
Expand All @@ -72,3 +80,27 @@
)
```
</CodeGroup>

## Access your app

Create a sandbox and grab the URL. The dev server with Turbopack is already running on port 3000.

Check warning on line 86 in docs/template/examples/nextjs-bun.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/template/examples/nextjs-bun.mdx#L86

Did you really mean 'Turbopack'?

<CodeGroup>
```typescript JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('nextjs-app-bun', { timeoutMs: 60_000 })

const url = sandbox.getHost(3000)
console.log('Next.js app running at:', url)
```

```python Python
from e2b import Sandbox

sandbox = Sandbox.create('nextjs-app-bun', timeout=60)

url = sandbox.get_host(3000)
print('Next.js app running at:', url)
```
</CodeGroup>
Loading