Skip to content

Repository files navigation

Code Capsule

Describe an app. Watch it get written, then run — live, in a sandbox, in the browser.

Watch the build E2B Vercel AI SDK Next.js

Build a Code Capsule — instantly generate and preview UI code with AI


What it does

You type what you want. A model writes the code, streaming it into the editor as it goes. The result is then executed in a real E2B sandbox — a fresh container with the dependencies already installed — and the running app is streamed back into an iframe beside the code.

Not a preview of what the code might do. The actual thing, running.

19 models across 8 providers. OpenAI (o1-preview, o1-mini, gpt-4o, gpt-4o-mini, gpt-4-turbo), Anthropic (claude-3-5-sonnet), Google (gemini-1.5-pro-002, gemini-1.5-flash-002), Mistral, Groq, Fireworks, Together AI, and local models through Ollama.

Four sandbox templates, each a prebuilt E2B image: Next.js, Vue/Nuxt, Streamlit and Gradio. Next.js is the one wired up in lib/templates.json — the other three are built and ready, and enabling one is a single entry in that file.

Rate limiting through Vercel KV, so a public deployment does not become someone else's free inference.

Stack

Framework Next.js App Router, TypeScript
Model routing Vercel AI SDK — @ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/google, @ai-sdk/mistral, ollama-ai-provider
Execution @e2b/code-interpreter — one sandbox per generation
Auth Supabase (optional, off by default)
Rate limiting Vercel KV
Analytics PostHog (optional, off by default)
UI Tailwind CSS, Radix UI

Running it locally

git clone https://github.com/kuluruvineeth/codecapsule.git
cd codecapsule
npm install

Create .env.local. Only the E2B key and one model provider are required:

E2B_API_KEY=                     # https://e2b.dev/docs/getting-started/api-key
ANTHROPIC_API_KEY=               # or any one of the providers below
OPENAI_API_KEY=
GROQ_API_KEY=
FIREWORKS_API_KEY=
TOGETHER_AI_API_KEY=
GOOGLE_GENERATIVE_AI_API_KEY=
MISTRAL_API_KEY=

# optional
KV_REST_API_URL=                 # rate limiting
KV_REST_API_TOKEN=
RATE_LIMIT_MAX_REQUESTS=
RATE_LIMIT_WINDOW=
NEXT_PUBLIC_ENABLE_SUPABASE=false
NEXT_PUBLIC_ENABLE_POSTHOG=false
npm run dev

Open http://localhost:3000.

Building your own sandbox template

Each template in sandbox-templates/ is a Dockerfile plus an e2b.toml. To build and register one:

cd sandbox-templates/streamlit-developer
e2b template build

Then add its entry to lib/templates.json.

Watch it being built

▶ Build a Code Capsule: Instantly Generate & Preview UI Code with AI


Built by @kuluruvineeth — I build AI products and take them apart on camera.

About

Describe an app, watch it run. Multi-model code generation into live E2B sandboxes — Next.js, Vue, Streamlit and Gradio templates.

Topics

Resources

Stars

21 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages