Skip to content
reaatech

Files · Anthropic Code Sandbox for SMB Data Analysis

55 (0 binary, 280.1 kB total)attempt 3

README.md·2550 B·markdown
markdown
# Anthropic Code Sandbox for SMB Data Analysis
 
Turn plain-English questions into safe, budget-controlled data analyses in a secure sandbox.
 
## Problem
 
Small businesses collect sales, inventory, and customer data but can't afford a data analyst. They need a way to ask business questions in plain language and receive trustworthy, actionable answers without risking runaway cloud costs or data breaches.
 
## Solution
 
This recipe lets SMBs upload CSVs or connect databases and ask natural-language questions. Claude generates Python code that executes in an E2B sandbox; REAA's agent-budget-engine and spend-tracker enforce per-query cost limits, circuit-breaker-core prevents infinite loops, agent-eval-harness-judge quality-gates the output, and agent-memory stores past analyses for context reuse.
 
## Architecture
 
```
Frontend (Next.js App Router)
├── Dashboard page (ask questions, upload CSVs)
├── History page (past analyses with costs)
└── API routes
    ├── POST /api/analyze  (Claude → E2B sandbox → evaluation)
    ├── GET  /api/history  (spend + memory lookup)
    └── POST /api/upload   (CSV validation + schema extraction)
 
Backend glue (src/lib)
├── Anthropic client
├── Budget controller (define / check / record)
├── Spend store
├── Pricing provider
├── Circuit breakers (LLM + sandbox)
├── E2B sandbox executor
├── Judge / eval engine
├── Memory (AgentMemory + retriever)
└── Prompt builder
```
 
## Setup
 
1. Copy `.env.example` to `.env.local` and fill in keys:
   - `ANTHROPIC_API_KEY` — from https://platform.claude.com/settings/keys
   - `E2B_API_KEY` — from https://e2b.dev/dashboard?tab=keys
   - `OPENAI_API_KEY` — for embeddings (memory retrieval)
 
2. Install dependencies:
   ```bash
   pnpm install
   ```
 
3. Run the dev server:
   ```bash
   pnpm dev
   ```
 
## Usage
 
Ask a question via curl:
```bash
curl -X POST http://localhost:3000/api/analyze \
  -H "Content-Type: application/json" \
  -H "x-api-key: demo" \
  -d '{"question":"What is the sales trend?","userId":"demo"}'
```
 
Upload a CSV:
```bash
curl -X POST http://localhost:3000/api/upload \
  -H "x-api-key: demo" \
  -F "file=@sales.csv"
```
 
## Testing
 
```bash
pnpm typecheck
pnpm lint
pnpm test
```
 
## Tech Stack
 
- Next.js 15 (App Router)
- React 19
- TypeScript 5
- Anthropic Claude SDK
- E2B Code Interpreter
- REAA agent-budget / memory / circuit-breaker / eval packages
- Zod validation
- Vitest + MSW + @testing-library/react
 
## License
 
MIT