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

2

Authenticate with E2B

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

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

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:
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:
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:
Get your API key from the E2B dashboard.

Sandbox lifecycle

Configuration reference

These settings control sandbox behavior in vibracode-backend/.env.local:

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