You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: docs/use-cases/vibe-coding.mdx
+32-32Lines changed: 32 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,44 +4,44 @@ description: "Build AI-powered app generators that turn natural language into ru
4
4
icon: "wand-magic-sparkles"
5
5
---
6
6
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.
8
8
9
9
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).
10
10
11
11
## How It Works
12
12
13
13
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.)
15
15
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
18
18
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
20
20
21
-
## Install the E2B SDK
21
+
## Install the E2B Code Interpreter SDK
22
22
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.
24
24
25
25
<CodeGroup>
26
26
```bash JavaScript & TypeScript
27
-
npm i e2b
27
+
npm i @e2b/code-interpreter
28
28
```
29
29
```bash Python
30
-
pip install e2b
30
+
pip install e2b-code-interpreter
31
31
```
32
32
</CodeGroup>
33
33
34
34
## Core Implementation
35
35
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).
37
37
38
38
### Creating a sandbox from a template
39
39
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.
41
41
42
42
<CodeGroup>
43
43
```typescript JavaScript & TypeScript
44
-
import { Sandbox } from'e2b'
44
+
import { Sandbox } from'@e2b/code-interpreter'
45
45
46
46
// Create a sandbox from a pre-configured Next.js template
47
47
// The dev server starts automatically via the template's start command
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.
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.
@@ -165,11 +165,11 @@ print("Preview your app at:", preview_url)
165
165
166
166
### Putting it all together
167
167
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.
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)
260
260
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
262
262
4.**Write generated code** — `files.write()` places the code in the sandbox [filesystem](/docs/filesystem/read-write) at the path the framework expects
263
263
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
0 commit comments