From f654caec507ebb6199f054e9f855ed987741d15a Mon Sep 17 00:00:00 2001 From: Peter Wielander Date: Thu, 2 Apr 2026 17:23:30 -0700 Subject: [PATCH 1/2] accept Web WritableStream in runCommand stdout/stderr runCommand now accepts both Node.js Writable and Web WritableStream for stdout/stderr options. The conversion happens inside the step (where Node.js APIs are available), so workflow code can pass Web streams from getWritable() directly. --- packages/vercel-sandbox/src/sandbox.ts | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/vercel-sandbox/src/sandbox.ts b/packages/vercel-sandbox/src/sandbox.ts index 2a895c5..cdff14a 100644 --- a/packages/vercel-sandbox/src/sandbox.ts +++ b/packages/vercel-sandbox/src/sandbox.ts @@ -154,13 +154,15 @@ interface RunCommandParams { */ detached?: boolean; /** - * A `Writable` stream where `stdout` from the command will be piped + * A stream where `stdout` from the command will be piped. + * Accepts a Node.js `Writable` or a Web `WritableStream`. */ - stdout?: Writable; + stdout?: Writable | WritableStream; /** - * A `Writable` stream where `stderr` from the command will be piped + * A stream where `stderr` from the command will be piped. + * Accepts a Node.js `Writable` or a Web `WritableStream`. */ - stderr?: Writable; + stderr?: Writable | WritableStream; /** * An AbortSignal to cancel the command execution */ @@ -501,12 +503,27 @@ export class Sandbox { return; } + // Resolve writers: support both Node.js Writable and Web WritableStream + const getWriter = ( + stream: Writable | WritableStream | undefined, + ): { write: (data: string) => void } | undefined => { + if (!stream) return undefined; + if ("getWriter" in stream) { + const writer = stream.getWriter(); + return { write: (data: string) => writer.write(data) }; + } + return stream; + }; + + const stdoutWriter = getWriter(params.stdout); + const stderrWriter = getWriter(params.stderr); + try { for await (const log of command.logs({ signal: params.signal })) { if (log.stream === "stdout") { - params.stdout?.write(log.data); + stdoutWriter?.write(log.data); } else if (log.stream === "stderr") { - params.stderr?.write(log.data); + stderrWriter?.write(log.data); } } } catch (err) { From e004eeb26bc7c407b8ceca049abce71c1702c1ed Mon Sep 17 00:00:00 2001 From: Pranay Prakash Date: Fri, 27 Mar 2026 16:07:31 -0700 Subject: [PATCH 2/2] fix typecheck: guard .emit() call for WritableStream compatibility Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/vercel-sandbox/src/sandbox.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vercel-sandbox/src/sandbox.ts b/packages/vercel-sandbox/src/sandbox.ts index cdff14a..cfdf14c 100644 --- a/packages/vercel-sandbox/src/sandbox.ts +++ b/packages/vercel-sandbox/src/sandbox.ts @@ -584,7 +584,10 @@ export class Sandbox { if (params.signal?.aborted) { return; } - (params.stderr ?? params.stdout)?.emit("error", err); + const errStream = params.stderr ?? params.stdout; + if (errStream && "emit" in errStream) { + errStream.emit("error", err); + } }); return command;