e2b-durable-endpoints-chatgpt-containers

1
0
1
12
TypeScript
public

ChatGPT Containers with E2B and Durable Endpoints

An AI data analyst that replicates the ChatGPT Containers pattern: a persistent sandbox where code execution state survives across conversation turns.

Built with E2B (cloud sandboxes), Durable Endpoints (with Inngest), and Claude.

How it works

  1. User asks a data question
  2. Claude writes Python code to fetch, analyze, and visualize data
  3. Code runs in a persistent E2B sandbox (pandas, matplotlib, etc. pre-installed)
  4. Claude analyzes the results and responds
  5. Follow-up messages reuse the same sandbox, so variables and data persist

Each LLM call and code execution is a durable step (step.run()). If anything fails, Inngest retries from the last successful checkpoint.

Setup

git clone https://github.com/inngest/e2b-durable-endpoints-chatgpt-containers.git
cd e2b-durable-endpoints-chatgpt-containers
npm install

Create a .env.local file:

ANTHROPIC_API_KEY=your-anthropic-key
E2B_API_KEY=your-e2b-key

# Optional: enables the web_search tool
EXA_API_KEY=your-exa-key

Run the application and Inngestdev server:

npx inngest-cli@latest dev
npm run dev

Open http://localhost:3000.

Project structure

src/
  app/
    api/
      chat/route.ts       # Durable endpoint: LLM + E2B tool-calling loop
      events/route.ts      # Polling endpoint for progress events
    page.tsx               # Chat UI
  components/
    ChatMessage.tsx        # Message rendering (code blocks, charts, search results)
    ChatInput.tsx          # Input field
    CodeBlock.tsx          # Collapsible code display
    ChartImage.tsx         # Base64 chart rendering
  hooks/
    useChat.ts             # Chat state + event polling
  inngest/
    client.ts              # Inngest client config
    execute-code.ts        # E2B code execution wrapper
    mcp-client.ts          # Sandbox creation + Exa search
    event-store.ts         # In-memory event store with dedup
    types.ts               # Shared types

Key features

Persistent sandbox: the E2B sandbox stays alive for 30 minutes. Ask “load this data”, then “filter by 2025”, then “chart it”. Each step builds on the previous state.

Durable execution: every LLM call and code execution is wrapped in step.run(). If the server crashes mid-conversation, Inngest replays from the last checkpoint.

Web search (optional): if EXA_API_KEY is set, Claude gets a web_search tool to find data sources before writing code.

v0.3.3[beta]