Skip to content

feat(sdk): add opt-in stdin for detached commands - #365

Merged
kishorekrd merged 12 commits into
mainfrom
kishore/command-stdin
Oct 9, 2026
Merged

kishorekrd merged 12 commits into
mainfrom
kishore/command-stdin

Conversation

@kishorekrd

@kishorekrd kishorekrd commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds stdin for commands, mainly to run stdio MCP servers (like agent-browser mcp) in a sandbox.

const cmd = await sandbox.runCommand({ cmd: "cat", stdin: true, detached: true });
await cmd.writeStdin("hello\n");
await cmd.closeStdin();

// or pipe a stream, with or without detached
await sandbox.runCommand({ cmd: "agent-browser", args: ["mcp"], stdin: process.stdin, stdout: process.stdout });
  • stdin: true needs detached: true. A Readable is written in order with backpressure, and stdin closes when it ends. The caller's stream is never destroyed.
  • If piping fails, runCommand rejects and kills the command. When detached, the next wait() rejects instead.
  • Each request carries its stdin position, so retries on 429, 502, 503, 504 and network errors never duplicate bytes. If a write still fails, later writes are rejected, but closeStdin still works.
  • In workflows, step retries are off and each step continues from the server's position.
  • @vercel/sandbox-mock support is a follow-up.

Needs backend support that ships separately. The integration tests fail until it's deployed.

runCommand accepts `stdin: true` (detached only), and Command gains
writeStdin() and closeStdin(). Writes are serialized per command, split
into 512 KiB chunks, and never retried so bytes can't be delivered twice.
@vercel

vercel Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
sandbox Ready Ready Preview, v0 Oct 9, 2026 6:54pm UTC
sandbox-cli Ready Ready Preview Oct 9, 2026 6:54pm UTC
sandbox-sdk-ai-example Ready Ready Preview Oct 9, 2026 6:54pm UTC
workflow-code-runner Ready Ready Preview Oct 9, 2026 6:54pm UTC

Request Review

Workflow DevKit retries failed steps by default, which could resend
stdin bytes, so writeStdin and closeStdin now run with maxRetries 0.
Rate limited writes are retried again since they were never applied.
A write that fails after possibly delivering data now blocks later
writes instead of appending to a partial message, an abort while
waiting in the queue takes effect, and CommandFinished rejects stdin
calls with a clear error.
Each workflow step gets a freshly deserialized Command, so the write queue and the rejection after a failed write don't carry across steps.
Each stdin request now carries the position it starts at, so a request that
fails on a dropped connection or a restarting server is resent without
delivering the same bytes twice. Timeouts are only resent while the process
keeps reading.
Passing a Readable such as process.stdin as `stdin` pipes it to the command
and closes stdin when it ends, with or without `detached`.
@kishorekrd
kishorekrd marked this pull request as ready for review October 8, 2026 21:00
- Close stdin at the position the API reports once a write has failed, instead
  of a stale one the API rejects.
- Treat a client error that follows a resent request as possibly written, so
  later writes are rejected.
- Use the bytes written a timeout reports instead of asking for them.
- Report a stream failure to one wait() and let later calls wait for exit,
  keep piping when a wait is aborted, close stdin when the stream is destroyed
  before it ends, and read a stream the caller paused.
Comment thread packages/vercel-sandbox/src/command.ts
Comment thread packages/vercel-sandbox/src/command.ts Outdated
Comment thread packages/vercel-sandbox/src/utils/pipe-stdin.ts

This branch was successfully deployed

4 active deployments
Preview – sandbox-sdk-ai-example — 2dca644a Deployed Oct 9, 2026 by vercel[bot]
Preview – workflow-code-runner — 2dca644a Deployed Oct 9, 2026 by vercel[bot]
Preview – sandbox — 2dca644a Deployed Oct 9, 2026 by vercel[bot]
Preview – sandbox-cli — 2dca644a Deployed Oct 9, 2026 by vercel[bot]
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.

2 participants