Skip to main content
Create and initialize a new sandbox environment where AI-generated code runs with live preview. The sandbox includes a complete React + Vite + Tailwind setup.

Endpoints

There are two versions depending on your sandbox provider:
EndpointProviderDescription
/api/create-ai-sandboxVercelCreates a Vercel Sandbox instance
/api/create-ai-sandbox-v2ModalCreates a Modal cloud sandbox (recommended)

Create Sandbox (Vercel)

POST /api/create-ai-sandbox
No request body required. Creates a Vercel sandbox with automatic Vite React setup.

Response

{
  "success": true,
  "sandboxId": "sbx_abc123xyz",
  "url": "https://sbx-abc123xyz.vercel.run:3000",
  "message": "Vercel sandbox created and Vite React app initialized"
}

Create Sandbox V2 (Modal)

POST /api/create-ai-sandbox-v2
Creates a sandbox using the Modal cloud backend with Seemodo AI integration.

Request Body

forceNew
boolean
default:"false"
Force creation of a new sandbox even if one already exists.

Response

{
  "success": true,
  "sandboxId": "modal-sandbox-1234",
  "url": "https://seemodo--sandbox-1234.modal.run",
  "apiUrl": "https://seemodo--sandbox-backend.modal.run",
  "message": "Modal sandbox created successfully"
}

Sandbox Initialization

When a sandbox is created, it’s automatically set up with:
1

Project Structure

Creates a complete Vite React project with TypeScript support.
2

Dependencies

Installs React, Tailwind CSS, and common UI dependencies.
3

Vite Configuration

Configures HMR (Hot Module Replacement) for live updates.
4

Dev Server

Starts the Vite dev server and returns the preview URL.

Project Template

The created sandbox includes:
/
├── package.json          # Dependencies and scripts
├── vite.config.js        # Vite with React and HMR
├── tailwind.config.js    # Tailwind configuration
├── postcss.config.js     # PostCSS setup
├── index.html            # HTML entry point
└── src/
    ├── main.jsx          # React entry
    ├── App.tsx           # Main app component
    ├── index.css         # Tailwind imports
    └── pages/            # Generated pages go here

Example Usage

// Create a new sandbox
const response = await fetch('/api/create-ai-sandbox-v2', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ forceNew: false })
});

const { sandboxId, url } = await response.json();

// Now use the sandbox for generation
await fetch('/api/generate-screen', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'A beautiful landing page',
    sandboxId: sandboxId
  })
});

// Preview is available at the returned URL
console.log('Preview:', url);

Sandbox Lifecycle

Reusing Existing Sandboxes

The API automatically reuses existing sandboxes when possible:
// First call creates a new sandbox
await fetch('/api/create-ai-sandbox-v2', { method: 'POST' });

// Second call returns the existing sandbox
await fetch('/api/create-ai-sandbox-v2', { method: 'POST' });

// Force a new sandbox
await fetch('/api/create-ai-sandbox-v2', {
  method: 'POST',
  body: JSON.stringify({ forceNew: true })
});

Error Handling

ErrorCauseSolution
Sandbox creation already in progressConcurrent creation requestsWait for existing creation
Failed to create sandboxProvider errorCheck provider credentials
npm install failedDependency issuesRetry or check template

Error Response

{
  "error": "Failed to create sandbox",
  "details": "Modal backend not responding"
}

Configuration

Sandbox behavior is configured in config/app.config.ts:
modal: {
  enabled: true,
  timeoutMinutes: 60,
  defaultPort: 5173,
  workDir: '/root/vite-app'
},
vercelSandbox: {
  timeoutMinutes: 30,
  devPort: 3000,
  runtime: 'nodejs20'
}

Environment Variables

VariableDescription
MODAL_BACKEND_URLURL to Modal backend API
VERCEL_TOKENVercel API token (for Vercel provider)
VERCEL_TEAM_IDVercel team ID
VERCEL_PROJECT_IDVercel project ID

Notes

  • Sandboxes timeout after the configured duration (default 60 minutes)
  • Modal sandboxes include Seemodo AI for intelligent code generation
  • Vercel sandboxes are lighter but don’t include Seemodo AI
  • Only one sandbox is typically active at a time per session