Skip to main content
Every time a user creates a new app, Vibra Code spawns an isolated E2B cloud sandbox. The sandbox runs the AI agent, clones the Expo template, installs dependencies, starts the Expo dev server, and creates a tunnel URL so the phone can preview the running app. You need to build and publish a custom E2B sandbox template before any of this will work.

What happens inside a sandbox

When a session starts, the sandbox goes through these steps:
  1. Clone — clones the Expo template from https://github.com/sa4hnd/expo-template
  2. Install — runs npm install to install JS dependencies
  3. Start dev server — starts npx expo start --tunnel --port 3000
  4. Create tunnel — Expo creates a public tunnel URL for the phone preview
  5. Run agent — the AI agent generates code by editing files in the sandbox
  6. Stream updates — file changes are streamed back to Convex in real time
Sandboxes auto-pause after inactivity (default: 10 minutes, controlled by AUTO_PAUSE_TIMEOUT_MS).

Build the template

1

Install the E2B CLI

npm install -g @e2b/cli
2

Authenticate with E2B

e2b auth login
This opens a browser window to log in to your E2B account. You need an account at e2b.dev — sign up for free.
3

Navigate to the template directory

cd vibracode-backend/e2b-cursor-template
This directory contains the Dockerfile that defines the sandbox environment — the base OS, installed tools, and any pre-installed dependencies.
4

Build and publish the template

e2b template build
This builds the Docker image, pushes it to E2B, and returns a template ID. The build can take a few minutes on first run.Example output:
✓ Template built successfully
Template ID: abc123xyz
Save this template ID — you’ll need it in the next step.
5

Set the template ID in config

Open vibracode-backend/config.ts and replace YOUR_E2B_TEMPLATE_ID with your template ID:
image: "YOUR_E2B_TEMPLATE_ID", // replace with your template ID
Also update vibracode-backend/lib/e2b/config.ts with the same template ID if it has a separate reference.
6

Set the E2B API key

Make sure E2B_API_KEY is set in your vibracode-backend/.env.local:
E2B_API_KEY=your_api_key_here
Get your API key from the E2B dashboard.

Sandbox lifecycle

User sends message

Inngest queues create-session

E2B sandbox created from your template

Expo template cloned + deps installed

Dev server started + tunnel created

AI agent runs (run-agent Inngest function)

Code changes streamed to Convex → phone

No activity → sandbox auto-pauses

Configuration reference

These settings control sandbox behavior in vibracode-backend/.env.local:
VariableDefaultDescription
E2B_API_KEYRequired. Your E2B API key.
AUTO_PAUSE_TIMEOUT_MS600000Milliseconds of inactivity before a sandbox auto-pauses. Default is 10 minutes.

Rebuilding the template

If you change the Dockerfile or want to update system dependencies in the sandbox, run e2b template build again. You’ll get a new template ID — update config.ts and redeploy your backend.
Keep the old template ID around until you’ve verified the new one works. E2B doesn’t delete old templates automatically, so existing sessions will continue to use the previous image.

Next steps

Build docs developers (and LLMs) love