Skip to content

feat(sandbox,vercel-sandbox): support timeout parameter when executing a command#212

Open
marc-vercel wants to merge 2 commits into
mainfrom
sandbox-command-timeout
Open

feat(sandbox,vercel-sandbox): support timeout parameter when executing a command#212
marc-vercel wants to merge 2 commits into
mainfrom
sandbox-command-timeout

Conversation

@marc-vercel
Copy link
Copy Markdown
Collaborator

@marc-vercel marc-vercel commented May 28, 2026

Problem

When running a command in a sandbox you currently have to wrap the call yourself with an AbortController + setTimeout to enforce a deadline. This is verbose, easy to get wrong (forgotten clear, race with await), and the killed process can leak resources on the sandbox side because the cancellation only happens client-side.

Solution

SDK contract

runCommand accepts a new timeoutMs option. It is only meaningful for non-detached calls — combining it with detached: true throws a synchronous TypeError.

import { Sandbox } from "@vercel/sandbox";

const sandbox = await Sandbox.get({ name: "my-sandbox" });

const result = await sandbox.runCommand({
  cmd: "python",
  args: ["train.py"],
  timeoutMs: 30_000, // kill with SIGKILL after 30s
});

if (result.exitCode === 137) {
  console.log("training was killed by the timeout");
}

It's also exposed on the convenience overload:

await sandbox.runCommand("sleep", ["60"], { timeoutMs: 5_000 });

CLI contract

sandbox exec gets a --timeout flag that accepts a duration string (e.g. 30s, 5m). It cannot be combined with --interactive.

sandbox exec my-sandbox --timeout 30s -- python train.py

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sandbox Ready Ready Preview, Comment, Open in v0 May 28, 2026 4:44pm
sandbox-cli Ready Ready Preview, Comment May 28, 2026 4:44pm
sandbox-sdk Ready Ready Preview, Comment May 28, 2026 4:44pm
sandbox-sdk-ai-example Ready Ready Preview, Comment May 28, 2026 4:44pm
workflow-code-runner Ready Ready Preview, Comment May 28, 2026 4:44pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant