Skip to content

Commit 9cc948d

Browse files
committed
Use Code Interpreter SDK and clarify sandbox architecture
Switch imports from plain e2b to @e2b/code-interpreter to match Fragments' actual usage. Clarify that the app runs outside the sandbox, using it purely to prepare and serve the generated code.
1 parent 963b82a commit 9cc948d

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

docs/use-cases/vibe-coding.mdx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ description: "Build AI-powered app generators that turn natural language into ru
44
icon: "wand-magic-sparkles"
55
---
66

7-
Vibe coding tools let users describe an app in plain language and get back running code instantly. The challenge is executing AI-generated code safely — it could be buggy, resource-hungry, or malicious. E2B sandboxes solve this by providing isolated environments where generated code runs securely, with [public URLs](/docs/sandbox/internet-access) for live previews that users can open in their browser.
7+
Vibe coding tools let users describe an app in plain language and get back running code instantly. Your application handles the LLM interaction and UI, then uses E2B sandboxes as isolated environments to prepare and serve the generated app — installing dependencies, writing code files, and exposing a [public URL](/docs/sandbox/internet-access) for the live preview. Since the generated code never runs on your infrastructure, it can't cause damage even if it's buggy or malicious.
88

99
For a complete working implementation, see [Fragments](https://github.com/e2b-dev/fragments) — an open-source vibe coding platform you can try via the [live demo](https://fragments.e2b.dev).
1010

1111
## How It Works
1212

1313
1. **User describes what they want** — e.g., "Build a todo app with dark mode" or "Create a chart of monthly sales data"
14-
2. **Your backend sends the prompt to an LLM** — any model that can generate code (OpenAI, Anthropic, Google, Mistral, etc.)
14+
2. **Your app sends the prompt to an LLM** — any model that can generate code (OpenAI, Anthropic, Google, Mistral, etc.)
1515
3. **The LLM returns structured output** — generated code, a list of additional dependencies, and which framework to target
16-
4. **Your backend creates an E2B sandbox** — using a pre-configured [template](/docs/template/quickstart) that matches the target framework (e.g., Next.js, Streamlit, Python)
17-
5. **Dependencies are installed**`commands.run()` installs any extra packages the LLM requested
16+
4. **Your app creates an E2B sandbox** — using a pre-configured [template](/docs/template/quickstart) that matches the target framework (e.g., Next.js, Streamlit, Python)
17+
5. **Dependencies are installed in the sandbox**`commands.run()` installs any extra packages the LLM requested
1818
6. **Generated code is written to the sandbox**`files.write()` places the code at the correct file path
19-
7. **The app starts and becomes accessible**`getHost(port)` / `get_host(port)` returns a public URL the user can open in their browser
19+
7. **The sandbox serves the app**`getHost(port)` / `get_host(port)` returns a public URL your app embeds in an iframe for the user
2020

21-
## Install the E2B SDK
21+
## Install the E2B Code Interpreter SDK
2222

23-
The [E2B SDK](https://github.com/e2b-dev/e2b) lets you create sandboxes, write files, run commands, and retrieve public URLs for running apps.
23+
[Fragments](https://github.com/e2b-dev/fragments) uses the [E2B Code Interpreter SDK](https://github.com/e2b-dev/code-interpreter) — an extension of the base E2B SDK that adds code execution capabilities on top of sandbox management.
2424

2525
<CodeGroup>
2626
```bash JavaScript & TypeScript
27-
npm i e2b
27+
npm i @e2b/code-interpreter
2828
```
2929
```bash Python
30-
pip install e2b
30+
pip install e2b-code-interpreter
3131
```
3232
</CodeGroup>
3333

3434
## Core Implementation
3535

36-
The following snippets show the key building blocks for a vibe coding backend, adapted from [Fragments](https://github.com/e2b-dev/fragments).
36+
The following snippets show the key building blocks for a vibe coding backend. Your application (e.g., a Next.js server) runs these on its own infrastructure — the sandbox is used purely as the execution environment for the generated code. These examples are adapted from [Fragments](https://github.com/e2b-dev/fragments).
3737

3838
### Creating a sandbox from a template
3939

40-
Create a sandbox from a [custom template](/docs/template/quickstart) that has your target framework pre-installed. The template's start command (e.g., `npx next --turbo`) launches the dev server automatically, so the app is ready to serve as soon as the sandbox starts. See the [Next.js template example](/docs/template/examples/nextjs) for a full template definition.
40+
Create a sandbox from a [custom template](/docs/template/quickstart) that has your target framework pre-installed. The template's start command (e.g., `npx next --turbo`) launches the dev server automatically, so the sandbox is ready to serve as soon as it starts. See the [Next.js template example](/docs/template/examples/nextjs) for a full template definition.
4141

4242
<CodeGroup>
4343
```typescript JavaScript & TypeScript
44-
import { Sandbox } from 'e2b'
44+
import { Sandbox } from '@e2b/code-interpreter'
4545

4646
// Create a sandbox from a pre-configured Next.js template
4747
// The dev server starts automatically via the template's start command
@@ -52,7 +52,7 @@ const sandbox = await Sandbox.create('nextjs-app', {
5252
console.log('Sandbox created:', sandbox.sandboxId)
5353
```
5454
```python Python
55-
from e2b import Sandbox
55+
from e2b_code_interpreter import Sandbox
5656

5757
# Create a sandbox from a pre-configured Next.js template
5858
# The dev server starts automatically via the template's start command
@@ -64,11 +64,11 @@ print("Sandbox created:", sandbox.sandbox_id)
6464

6565
### Installing dependencies
6666

67-
The LLM may request packages that aren't included in the template. Install them at runtime with `commands.run()` before writing the generated code. See [Install custom packages](/docs/quickstart/install-custom-packages) for more details.
67+
The LLM may request packages that aren't included in the template. Install them in the sandbox with `commands.run()` before writing the generated code. See [Install custom packages](/docs/quickstart/install-custom-packages) for more details.
6868

6969
<CodeGroup>
7070
```typescript JavaScript & TypeScript
71-
import { Sandbox } from 'e2b'
71+
import { Sandbox } from '@e2b/code-interpreter'
7272

7373
const sandbox = await Sandbox.create('nextjs-app', { timeoutMs: 300_000 })
7474

@@ -77,7 +77,7 @@ const dependencies = ['recharts', '@radix-ui/react-icons']
7777
await sandbox.commands.run(`npm install ${dependencies.join(' ')}`)
7878
```
7979
```python Python
80-
from e2b import Sandbox
80+
from e2b_code_interpreter import Sandbox
8181

8282
sandbox = Sandbox.create("nextjs-app", timeout=300)
8383

@@ -93,7 +93,7 @@ Once the LLM generates code, write it to the correct file path in the sandbox. T
9393

9494
<CodeGroup>
9595
```typescript JavaScript & TypeScript
96-
import { Sandbox } from 'e2b'
96+
import { Sandbox } from '@e2b/code-interpreter'
9797

9898
const sandbox = await Sandbox.create('nextjs-app', { timeoutMs: 300_000 })
9999

@@ -111,7 +111,7 @@ export default function Home() {
111111
await sandbox.files.write('/home/user/pages/index.tsx', generatedCode)
112112
```
113113
```python Python
114-
from e2b import Sandbox
114+
from e2b_code_interpreter import Sandbox
115115

116116
sandbox = Sandbox.create("nextjs-app", timeout=300)
117117

@@ -132,11 +132,11 @@ sandbox.files.write("/home/user/pages/index.tsx", generated_code)
132132

133133
### Getting the preview URL
134134

135-
After writing the code, the dev server (already running via the template's start command) picks up the changes automatically. Retrieve the sandbox's [public URL](/docs/sandbox/internet-access) and send it to your frontend so the user can see the running app.
135+
After writing the code, the dev server (already running via the template's start command) picks up the changes automatically. Retrieve the sandbox's [public URL](/docs/sandbox/internet-access) and send it to your frontend so the user can see the running app in an iframe.
136136

137137
<CodeGroup>
138138
```typescript JavaScript & TypeScript
139-
import { Sandbox } from 'e2b'
139+
import { Sandbox } from '@e2b/code-interpreter'
140140

141141
const sandbox = await Sandbox.create('nextjs-app', { timeoutMs: 300_000 })
142142

@@ -149,7 +149,7 @@ const previewUrl = `https://${host}`
149149
console.log('Preview your app at:', previewUrl)
150150
```
151151
```python Python
152-
from e2b import Sandbox
152+
from e2b_code_interpreter import Sandbox
153153

154154
sandbox = Sandbox.create("nextjs-app", timeout=300)
155155

@@ -165,11 +165,11 @@ print("Preview your app at:", preview_url)
165165

166166
### Putting it all together
167167

168-
Here is a complete example that demonstrates the full vibe coding flow: prompting an LLM, creating a sandbox, installing dependencies, writing the generated code, and returning a preview URL. This is a simplified version of how [Fragments](https://github.com/e2b-dev/fragments) handles each generation request.
168+
Here is a complete example that demonstrates the full vibe coding flow: prompting an LLM, creating a sandbox, installing dependencies, writing the generated code, and returning a preview URL. Your application orchestrates this from its own server — the sandbox handles only the generated app. This is a simplified version of how [Fragments](https://github.com/e2b-dev/fragments) handles each generation request.
169169

170170
<CodeGroup>
171171
```typescript JavaScript & TypeScript expandable
172-
import { Sandbox } from 'e2b'
172+
import { Sandbox } from '@e2b/code-interpreter'
173173
import OpenAI from 'openai'
174174

175175
// --- 1. Get code from the LLM ---
@@ -192,17 +192,17 @@ const response = await openai.chat.completions.create({
192192
const generatedCode = response.choices[0].message.content
193193
const dependencies = [''] // The LLM could also return a dependency list
194194

195-
// --- 2. Create a sandbox from the Next.js template ---
195+
// --- 2. Create a sandbox to prepare the generated app ---
196196
const sandbox = await Sandbox.create('nextjs-app', {
197197
timeoutMs: 300_000,
198198
})
199199

200-
// --- 3. Install any additional dependencies ---
200+
// --- 3. Install any additional dependencies in the sandbox ---
201201
if (dependencies.length > 0 && dependencies[0] !== '') {
202202
await sandbox.commands.run(`npm install ${dependencies.join(' ')}`)
203203
}
204204

205-
// --- 4. Write the generated code ---
205+
// --- 4. Write the generated code to the sandbox ---
206206
await sandbox.files.write('/home/user/pages/index.tsx', generatedCode)
207207

208208
// --- 5. Get the preview URL ---
@@ -214,7 +214,7 @@ console.log('App is live at:', previewUrl)
214214
await sandbox.kill()
215215
```
216216
```python Python expandable
217-
from e2b import Sandbox
217+
from e2b_code_interpreter import Sandbox
218218
from openai import OpenAI
219219

220220
# --- 1. Get code from the LLM ---
@@ -236,14 +236,14 @@ response = client.chat.completions.create(
236236
generated_code = response.choices[0].message.content
237237
dependencies = [] # The LLM could also return a dependency list
238238

239-
# --- 2. Create a sandbox from the Next.js template ---
239+
# --- 2. Create a sandbox to prepare the generated app ---
240240
sandbox = Sandbox.create("nextjs-app", timeout=300)
241241

242-
# --- 3. Install any additional dependencies ---
242+
# --- 3. Install any additional dependencies in the sandbox ---
243243
if dependencies:
244244
sandbox.commands.run(f"npm install {' '.join(dependencies)}")
245245

246-
# --- 4. Write the generated code ---
246+
# --- 4. Write the generated code to the sandbox ---
247247
sandbox.files.write("/home/user/pages/index.tsx", generated_code)
248248

249249
# --- 5. Get the preview URL ---
@@ -256,9 +256,9 @@ sandbox.kill()
256256
```
257257
</CodeGroup>
258258

259-
1. **Get code from the LLM**send a prompt to any model; the LLM returns generated code and optionally a list of dependencies — swap the model for any provider via [Connect LLMs](/docs/quickstart/connect-llms)
259+
1. **Get code from the LLM**your app sends a prompt to any model; the LLM returns generated code and optionally a list of dependencies — swap the model for any provider via [Connect LLMs](/docs/quickstart/connect-llms)
260260
2. **Create a sandbox**`Sandbox.create('nextjs-app')` spins up an isolated environment from a [custom template](/docs/template/quickstart) with the framework pre-installed and a dev server already running
261-
3. **Install dependencies**`commands.run()` installs any extra packages the LLM requested at runtime
261+
3. **Install dependencies**`commands.run()` installs any extra packages the LLM requested inside the sandbox
262262
4. **Write generated code**`files.write()` places the code in the sandbox [filesystem](/docs/filesystem/read-write) at the path the framework expects
263263
5. **Get the preview URL**`getHost(3000)` / `get_host(3000)` returns a public hostname; combine with `https://` to form the URL your frontend embeds in an iframe or opens in a new tab
264264

0 commit comments

Comments
 (0)