feat: make command parameter optional for POST /api/sandboxes#204
Conversation
Allow creating a sandbox without providing a command, which skips triggering the run-sandbox-command task. This enables users to simply create a sandbox environment without executing any commands. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe changes make the command field optional when creating sandboxes, allowing sandbox creation without immediately executing a command. The API documentation, request validation schema, and handler logic are updated to reflect this new behavior, with runId only returned when a command is provided. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Braintrust eval reportCatalog Opportunity Analysis Evaluation (HEAD-1770217418)
Catalog Songs Count Evaluation (HEAD-1770217418)
First Week Album Sales Evaluation (HEAD-1770217418)
Memory & Storage Tools Evaluation (HEAD-1770217418)
Monthly Listeners Tracking Evaluation (HEAD-1770217418)
Search Web Tool Evaluation (HEAD-1770217418)
Social Scraping Evaluation (HEAD-1770217418)
Spotify Followers Evaluation (HEAD-1770217418)
Spotify Tools Evaluation (HEAD-1770217418)
TikTok Analytics Questions Evaluation (HEAD-1770217418)
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@lib/sandbox/createSandboxPostHandler.ts`:
- Around line 43-57: The current catch in createSandboxPostHandler swallows
triggerRunSandboxCommand failures, making a missing runId indistinguishable from
"no command provided"; change the catch in the block that calls
triggerRunSandboxCommand to propagate a proper error response instead of just
logging: when triggerRunSandboxCommand({ command: validated.command, args:
validated.args, cwd: validated.cwd, sandboxId: result.sandboxId, accountId:
validated.accountId }) throws, rethrow or return a 4xx/5xx error (include the
original error message) so the handler returns failure to the client rather than
a success without runId; update any callers/response flow that rely on runId
accordingly.
🧹 Nitpick comments (1)
lib/sandbox/validateSandboxBody.ts (1)
8-10: Harden command validation against whitespace-only values.
min(1)still allows" ". Consider trimming before validation to avoid “empty but non-empty” commands.♻️ Suggested change
- command: z.string().min(1, "command cannot be empty").optional(), + command: z.string().trim().min(1, "command cannot be empty").optional(),
| // Trigger the command execution task only if a command was provided | ||
| let runId: string | undefined; | ||
| try { | ||
| const handle = await triggerRunSandboxCommand({ | ||
| command: validated.command, | ||
| args: validated.args, | ||
| cwd: validated.cwd, | ||
| sandboxId: result.sandboxId, | ||
| accountId: validated.accountId, | ||
| }); | ||
| runId = handle.id; | ||
| } catch (triggerError) { | ||
| console.error("Failed to trigger run-sandbox-command task:", triggerError); | ||
| if (validated.command) { | ||
| try { | ||
| const handle = await triggerRunSandboxCommand({ | ||
| command: validated.command, | ||
| args: validated.args, | ||
| cwd: validated.cwd, | ||
| sandboxId: result.sandboxId, | ||
| accountId: validated.accountId, | ||
| }); | ||
| runId = handle.id; | ||
| } catch (triggerError) { | ||
| console.error("Failed to trigger run-sandbox-command task:", triggerError); | ||
| } |
There was a problem hiding this comment.
Return an error when a requested command fails to trigger.
Right now a client can send command and still get a success response without runId if the trigger fails. That’s indistinguishable from “no command provided” and hides execution failures.
🐛 Suggested change
if (validated.command) {
try {
const handle = await triggerRunSandboxCommand({
command: validated.command,
args: validated.args,
cwd: validated.cwd,
sandboxId: result.sandboxId,
accountId: validated.accountId,
});
runId = handle.id;
} catch (triggerError) {
console.error("Failed to trigger run-sandbox-command task:", triggerError);
+ return NextResponse.json(
+ { status: "error", error: "Failed to run command in sandbox" },
+ { status: 502, headers: getCorsHeaders() },
+ );
}
}🤖 Prompt for AI Agents
In `@lib/sandbox/createSandboxPostHandler.ts` around lines 43 - 57, The current
catch in createSandboxPostHandler swallows triggerRunSandboxCommand failures,
making a missing runId indistinguishable from "no command provided"; change the
catch in the block that calls triggerRunSandboxCommand to propagate a proper
error response instead of just logging: when triggerRunSandboxCommand({ command:
validated.command, args: validated.args, cwd: validated.cwd, sandboxId:
result.sandboxId, accountId: validated.accountId }) throws, rethrow or return a
4xx/5xx error (include the original error message) so the handler returns
failure to the client rather than a success without runId; update any
callers/response flow that rely on runId accordingly.
Summary
commandparameter optional in POST /api/sandboxescommandis omitted, sandbox is created without triggering therun-sandbox-commandtaskrunIdfield is only included in the response when a command was providedTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit