diff --git a/app/api/sandboxes/route.ts b/app/api/sandboxes/route.ts index f922b0ec..ba07ce7f 100644 --- a/app/api/sandboxes/route.ts +++ b/app/api/sandboxes/route.ts @@ -20,7 +20,7 @@ export async function OPTIONS() { /** * POST /api/sandboxes * - * Creates a new ephemeral sandbox environment and executes a command. + * Creates a new ephemeral sandbox environment. Optionally executes a command. * Sandboxes are isolated Linux microVMs that can be used to evaluate * account-generated code, run AI agent output safely, or execute reproducible tasks. * The sandbox will automatically stop after the timeout period. @@ -28,13 +28,14 @@ export async function OPTIONS() { * Authentication: x-api-key header or Authorization Bearer token required. * * Request body: - * - command: string (required) - The command to execute in the sandbox + * - command: string (optional) - The command to execute in the sandbox. If omitted, sandbox is created without running any command. * - args: string[] (optional) - Arguments to pass to the command * - cwd: string (optional) - Working directory for command execution * * Response (200): * - status: "success" - * - sandboxes: [{ sandboxId, sandboxStatus, timeout, createdAt, runId }] + * - sandboxes: [{ sandboxId, sandboxStatus, timeout, createdAt, runId? }] + * - runId is only included when a command was provided * * Error (400/401): * - status: "error" diff --git a/lib/sandbox/createSandboxPostHandler.ts b/lib/sandbox/createSandboxPostHandler.ts index b01a79c3..86611710 100644 --- a/lib/sandbox/createSandboxPostHandler.ts +++ b/lib/sandbox/createSandboxPostHandler.ts @@ -10,13 +10,14 @@ import { selectAccountSnapshots } from "@/lib/supabase/account_snapshots/selectA /** * Handler for POST /api/sandboxes. * - * Creates a Vercel Sandbox (from account's snapshot if available, otherwise fresh) - * and triggers the run-sandbox-command task to execute the command. + * Creates a Vercel Sandbox (from account's snapshot if available, otherwise fresh). + * If a command is provided, triggers the run-sandbox-command task to execute it. + * If no command is provided, simply creates the sandbox without running any command. * Requires authentication via x-api-key header or Authorization Bearer token. * Saves sandbox info to the account_sandboxes table. * * @param request - The request object - * @returns A NextResponse with sandbox creation result including runId + * @returns A NextResponse with sandbox creation result (includes runId only if command was provided) */ export async function createSandboxPostHandler(request: NextRequest): Promise { const validated = await validateSandboxBody(request); @@ -39,19 +40,21 @@ export async function createSandboxPostHandler(request: NextRequest): Promise