@ai-sdk/tool-bash 1.0.30 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/tool-bash
2
2
 
3
+ ## 1.0.32
4
+
5
+ ### Patch Changes
6
+
7
+ - 1d2c2ff: Bound bash tool output collection before returning it from supporting sandbox adapters, and copy retained prefixes so truncated results do not keep large source strings alive. Preserve output text, omission counts, command completion, exit codes, and timeout behavior. Custom sandbox implementations remain compatible; just-bash's interpreter buffering remains subject to its native execution limits.
8
+ - Updated dependencies [0b8cbfa]
9
+ - Updated dependencies [6815153]
10
+ - Updated dependencies [15bfd6b]
11
+ - Updated dependencies [15bfd6b]
12
+ - Updated dependencies [2613bb4]
13
+ - Updated dependencies [63593a7]
14
+ - ai@7.0.178
15
+
16
+ ## 1.0.31
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [e403988]
21
+ - Updated dependencies [b792b56]
22
+ - ai@7.0.177
23
+
3
24
  ## 1.0.30
4
25
 
5
26
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["SandboxSession"],"sources":["../src/bash-tool.ts"],"mappings":";;;cAUM,aAAW,EAAA;;GAEf,EAAA,KAAA;cAEI,cAAY,EAAA;;;;GAIhB,EAAA,KAAA;KAEG,YAAY,EAAE,aAAa;KAE3B,aAAa,EAAE,aAAa;;;;;;;;;;;;;;;;iBAyBX,iBACpB,SACA,kBACA,iBACA;EAEA,SAASA;EACT;EACA;EACA;IACE,QACF,KAAK,WAAW;EACd,SAAS,oBAAoB,WAAW"}
1
+ {"version":3,"file":"index.d.ts","names":["SandboxSession"],"sources":["../src/bash-tool.ts"],"mappings":";;;cAUM,aAAW,EAAA;;GAEf,EAAA,KAAA;cAEI,cAAY,EAAA;;;;GAIhB,EAAA,KAAA;KAEG,YAAY,EAAE,aAAa;KAE3B,aAAa,EAAE,aAAa;;;;;;;;;;;;;;;;iBAgCX,iBACpB,SACA,kBACA,iBACA;EAEA,SAASA;EACT;EACA;EACA;IACE,QACF,KAAK,WAAW;EACd,SAAS,oBAAoB,WAAW"}
package/dist/index.js CHANGED
@@ -8,9 +8,9 @@ const outputSchema = z.object({
8
8
  stderr: z.string(),
9
9
  exitCode: z.number()
10
10
  });
11
- function limitOutput(output, maxLength) {
12
- if (output.length <= maxLength) return output;
13
- return `${output.slice(0, maxLength)}\n[Output truncated: ${output.length - maxLength} characters omitted.]`;
11
+ function limitOutput(output, maxLength, totalLength = output.length) {
12
+ if (totalLength <= maxLength) return output;
13
+ return `${output.slice(0, maxLength).split("").join("")}\n[Output truncated: ${totalLength - maxLength} characters omitted.]`;
14
14
  }
15
15
  /**
16
16
  * Create a provider-independent bash tool backed by a supplied sandbox session.
@@ -55,14 +55,15 @@ async function createBashTool({ sandbox, workingDirectory, maxOutputLength = 3e4
55
55
  execute: async ({ command }, { abortSignal }) => {
56
56
  const timeoutSignal = timeout === void 0 ? void 0 : AbortSignal.timeout(timeout);
57
57
  const commandSignal = timeoutSignal === void 0 ? abortSignal : abortSignal === void 0 ? timeoutSignal : AbortSignal.any([abortSignal, timeoutSignal]);
58
- const { stdout, stderr, exitCode } = await sandbox.run({
58
+ const { stdout, stderr, exitCode, stdoutLength, stderrLength } = await sandbox.run({
59
59
  command,
60
60
  ...workingDirectory !== void 0 ? { workingDirectory } : {},
61
- abortSignal: commandSignal
61
+ abortSignal: commandSignal,
62
+ maxOutputLength
62
63
  });
63
64
  return {
64
- stdout: limitOutput(stdout, maxOutputLength),
65
- stderr: limitOutput(stderr, maxOutputLength),
65
+ stdout: limitOutput(stdout, maxOutputLength, stdoutLength),
66
+ stderr: limitOutput(stderr, maxOutputLength, stderrLength),
66
67
  exitCode
67
68
  };
68
69
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/bash-tool.ts"],"sourcesContent":["import {\n InvalidArgumentError,\n tool,\n type Tool,\n type ToolExecuteFunction,\n type Experimental_SandboxSession as SandboxSession,\n} from 'ai';\nimport { posix } from 'node:path';\nimport { z } from 'zod/v4';\n\nconst inputSchema = z.object({\n command: z.string().describe('The Bash command or script to execute.'),\n});\n\nconst outputSchema = z.object({\n stdout: z.string(),\n stderr: z.string(),\n exitCode: z.number(),\n});\n\ntype BashInput = z.infer<typeof inputSchema>;\n\ntype BashOutput = z.infer<typeof outputSchema>;\n\nfunction limitOutput(output: string, maxLength: number): string {\n if (output.length <= maxLength) {\n return output;\n }\n\n return `${output.slice(0, maxLength)}\\n[Output truncated: ${output.length - maxLength} characters omitted.]`;\n}\n\n/**\n * Create a provider-independent bash tool backed by a supplied sandbox session.\n *\n * The caller owns the sandbox's lifecycle. Tools using the same session share\n * its files. Available commands and persistence depend on the sandbox.\n * Returns the tool; use the supplied sandbox for file access.\n *\n * @param sandbox - Sandbox session used for commands and file operations.\n * @param workingDirectory - Optional absolute starting directory for every\n * command, created if needed. When omitted, uses the sandbox's default directory.\n * @param maxOutputLength - Maximum characters retained from each output stream\n * before appending a truncation notice. Defaults to 30,000.\n * @param timeout - Optional timeout in milliseconds for each command execution.\n * Cancellation is forwarded to the sandbox along with the caller's abort signal.\n */\nexport async function createBashTool({\n sandbox,\n workingDirectory,\n maxOutputLength = 30_000,\n timeout,\n}: {\n sandbox: SandboxSession;\n workingDirectory?: string;\n maxOutputLength?: number;\n timeout?: number;\n}): Promise<\n Tool<BashInput, BashOutput, {}> & {\n execute: ToolExecuteFunction<BashInput, BashOutput, {}>;\n }\n> {\n if (\n timeout !== undefined &&\n (!Number.isInteger(timeout) || timeout < 1 || timeout > 2_147_483_647)\n ) {\n throw new InvalidArgumentError({\n parameter: 'timeout',\n value: timeout,\n message: 'Must be an integer between 1 and 2147483647 milliseconds.',\n });\n }\n\n if (!Number.isSafeInteger(maxOutputLength) || maxOutputLength < 1) {\n throw new InvalidArgumentError({\n parameter: 'maxOutputLength',\n value: maxOutputLength,\n message: 'Must be a positive safe integer.',\n });\n }\n\n if (workingDirectory !== undefined && !posix.isAbsolute(workingDirectory)) {\n throw new InvalidArgumentError({\n parameter: 'workingDirectory',\n value: workingDirectory,\n message: 'Must be an absolute path in the sandbox.',\n });\n }\n\n if (workingDirectory !== undefined) {\n workingDirectory = posix.normalize(workingDirectory);\n }\n\n if (workingDirectory !== undefined) {\n const directoryResult = await sandbox.run({\n command: `mkdir -p -- '${workingDirectory.replace(/'/g, \"'\\\\''\")}'`,\n });\n if (directoryResult.exitCode !== 0) {\n throw new Error(\n `Failed to create working directory: ${directoryResult.stderr}`,\n );\n }\n }\n\n return tool<BashInput, BashOutput, {}>({\n description:\n 'Run Bash commands in the sandbox. ' +\n (workingDirectory !== undefined\n ? `Every command starts in ${workingDirectory}. `\n : \"Commands run in the sandbox's default working directory. \") +\n 'Use ls to discover files and commands such as cat, grep, sort, awk, ' +\n 'and jq to inspect and transform them. Pipes and redirections are supported. ' +\n 'Returns stdout, stderr, and exitCode; long output is truncated.\\n' +\n sandbox.description,\n inputSchema,\n outputSchema,\n execute: async ({ command }, { abortSignal }) => {\n const timeoutSignal =\n timeout === undefined ? undefined : AbortSignal.timeout(timeout);\n const commandSignal =\n timeoutSignal === undefined\n ? abortSignal\n : abortSignal === undefined\n ? timeoutSignal\n : AbortSignal.any([abortSignal, timeoutSignal]);\n\n const { stdout, stderr, exitCode } = await sandbox.run({\n command,\n ...(workingDirectory !== undefined ? { workingDirectory } : {}),\n abortSignal: commandSignal,\n });\n\n return {\n stdout: limitOutput(stdout, maxOutputLength),\n stderr: limitOutput(stderr, maxOutputLength),\n exitCode,\n };\n },\n });\n}\n"],"mappings":";;;;AAUA,MAAM,cAAc,EAAE,OAAO,EAC3B,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,wCAAwC,EACvE,CAAC;AAED,MAAM,eAAe,EAAE,OAAO;CAC5B,QAAQ,EAAE,OAAO;CACjB,QAAQ,EAAE,OAAO;CACjB,UAAU,EAAE,OAAO;AACrB,CAAC;AAMD,SAAS,YAAY,QAAgB,WAA2B;CAC9D,IAAI,OAAO,UAAU,WACnB,OAAO;CAGT,OAAO,GAAG,OAAO,MAAM,GAAG,SAAS,EAAE,uBAAuB,OAAO,SAAS,UAAU;AACxF;;;;;;;;;;;;;;;;AAiBA,eAAsB,eAAe,EACnC,SACA,kBACA,kBAAkB,KAClB,WAUA;CACA,IACE,YAAY,KAAA,MACX,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,KAAK,UAAU,aAExD,MAAM,IAAI,qBAAqB;EAC7B,WAAW;EACX,OAAO;EACP,SAAS;CACX,CAAC;CAGH,IAAI,CAAC,OAAO,cAAc,eAAe,KAAK,kBAAkB,GAC9D,MAAM,IAAI,qBAAqB;EAC7B,WAAW;EACX,OAAO;EACP,SAAS;CACX,CAAC;CAGH,IAAI,qBAAqB,KAAA,KAAa,CAAC,MAAM,WAAW,gBAAgB,GACtE,MAAM,IAAI,qBAAqB;EAC7B,WAAW;EACX,OAAO;EACP,SAAS;CACX,CAAC;CAGH,IAAI,qBAAqB,KAAA,GACvB,mBAAmB,MAAM,UAAU,gBAAgB;CAGrD,IAAI,qBAAqB,KAAA,GAAW;EAClC,MAAM,kBAAkB,MAAM,QAAQ,IAAI,EACxC,SAAS,gBAAgB,iBAAiB,QAAQ,MAAM,OAAO,EAAE,GACnE,CAAC;EACD,IAAI,gBAAgB,aAAa,GAC/B,MAAM,IAAI,MACR,uCAAuC,gBAAgB,QACzD;CAEJ;CAEA,OAAO,KAAgC;EACrC,aACE,wCACC,qBAAqB,KAAA,IAClB,2BAA2B,iBAAiB,MAC5C,+DACJ,sNAGA,QAAQ;EACV;EACA;EACA,SAAS,OAAO,EAAE,WAAW,EAAE,kBAAkB;GAC/C,MAAM,gBACJ,YAAY,KAAA,IAAY,KAAA,IAAY,YAAY,QAAQ,OAAO;GACjE,MAAM,gBACJ,kBAAkB,KAAA,IACd,cACA,gBAAgB,KAAA,IACd,gBACA,YAAY,IAAI,CAAC,aAAa,aAAa,CAAC;GAEpD,MAAM,EAAE,QAAQ,QAAQ,aAAa,MAAM,QAAQ,IAAI;IACrD;IACA,GAAI,qBAAqB,KAAA,IAAY,EAAE,iBAAiB,IAAI,CAAC;IAC7D,aAAa;GACf,CAAC;GAED,OAAO;IACL,QAAQ,YAAY,QAAQ,eAAe;IAC3C,QAAQ,YAAY,QAAQ,eAAe;IAC3C;GACF;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/bash-tool.ts"],"sourcesContent":["import {\n InvalidArgumentError,\n tool,\n type Tool,\n type ToolExecuteFunction,\n type Experimental_SandboxSession as SandboxSession,\n} from 'ai';\nimport { posix } from 'node:path';\nimport { z } from 'zod/v4';\n\nconst inputSchema = z.object({\n command: z.string().describe('The Bash command or script to execute.'),\n});\n\nconst outputSchema = z.object({\n stdout: z.string(),\n stderr: z.string(),\n exitCode: z.number(),\n});\n\ntype BashInput = z.infer<typeof inputSchema>;\n\ntype BashOutput = z.infer<typeof outputSchema>;\n\nfunction limitOutput(\n output: string,\n maxLength: number,\n totalLength = output.length,\n): string {\n if (totalLength <= maxLength) {\n return output;\n }\n\n // Also copy prefixes returned by older or custom sandboxes, which may not\n // support bounded output and can return a substring backed by a large string.\n const prefix = output.slice(0, maxLength).split('').join('');\n return `${prefix}\\n[Output truncated: ${totalLength - maxLength} characters omitted.]`;\n}\n\n/**\n * Create a provider-independent bash tool backed by a supplied sandbox session.\n *\n * The caller owns the sandbox's lifecycle. Tools using the same session share\n * its files. Available commands and persistence depend on the sandbox.\n * Returns the tool; use the supplied sandbox for file access.\n *\n * @param sandbox - Sandbox session used for commands and file operations.\n * @param workingDirectory - Optional absolute starting directory for every\n * command, created if needed. When omitted, uses the sandbox's default directory.\n * @param maxOutputLength - Maximum characters retained from each output stream\n * before appending a truncation notice. Defaults to 30,000.\n * @param timeout - Optional timeout in milliseconds for each command execution.\n * Cancellation is forwarded to the sandbox along with the caller's abort signal.\n */\nexport async function createBashTool({\n sandbox,\n workingDirectory,\n maxOutputLength = 30_000,\n timeout,\n}: {\n sandbox: SandboxSession;\n workingDirectory?: string;\n maxOutputLength?: number;\n timeout?: number;\n}): Promise<\n Tool<BashInput, BashOutput, {}> & {\n execute: ToolExecuteFunction<BashInput, BashOutput, {}>;\n }\n> {\n if (\n timeout !== undefined &&\n (!Number.isInteger(timeout) || timeout < 1 || timeout > 2_147_483_647)\n ) {\n throw new InvalidArgumentError({\n parameter: 'timeout',\n value: timeout,\n message: 'Must be an integer between 1 and 2147483647 milliseconds.',\n });\n }\n\n if (!Number.isSafeInteger(maxOutputLength) || maxOutputLength < 1) {\n throw new InvalidArgumentError({\n parameter: 'maxOutputLength',\n value: maxOutputLength,\n message: 'Must be a positive safe integer.',\n });\n }\n\n if (workingDirectory !== undefined && !posix.isAbsolute(workingDirectory)) {\n throw new InvalidArgumentError({\n parameter: 'workingDirectory',\n value: workingDirectory,\n message: 'Must be an absolute path in the sandbox.',\n });\n }\n\n if (workingDirectory !== undefined) {\n workingDirectory = posix.normalize(workingDirectory);\n }\n\n if (workingDirectory !== undefined) {\n const directoryResult = await sandbox.run({\n command: `mkdir -p -- '${workingDirectory.replace(/'/g, \"'\\\\''\")}'`,\n });\n if (directoryResult.exitCode !== 0) {\n throw new Error(\n `Failed to create working directory: ${directoryResult.stderr}`,\n );\n }\n }\n\n return tool<BashInput, BashOutput, {}>({\n description:\n 'Run Bash commands in the sandbox. ' +\n (workingDirectory !== undefined\n ? `Every command starts in ${workingDirectory}. `\n : \"Commands run in the sandbox's default working directory. \") +\n 'Use ls to discover files and commands such as cat, grep, sort, awk, ' +\n 'and jq to inspect and transform them. Pipes and redirections are supported. ' +\n 'Returns stdout, stderr, and exitCode; long output is truncated.\\n' +\n sandbox.description,\n inputSchema,\n outputSchema,\n execute: async ({ command }, { abortSignal }) => {\n const timeoutSignal =\n timeout === undefined ? undefined : AbortSignal.timeout(timeout);\n const commandSignal =\n timeoutSignal === undefined\n ? abortSignal\n : abortSignal === undefined\n ? timeoutSignal\n : AbortSignal.any([abortSignal, timeoutSignal]);\n\n const { stdout, stderr, exitCode, stdoutLength, stderrLength } =\n await sandbox.run({\n command,\n ...(workingDirectory !== undefined ? { workingDirectory } : {}),\n abortSignal: commandSignal,\n maxOutputLength,\n });\n\n return {\n stdout: limitOutput(stdout, maxOutputLength, stdoutLength),\n stderr: limitOutput(stderr, maxOutputLength, stderrLength),\n exitCode,\n };\n },\n });\n}\n"],"mappings":";;;;AAUA,MAAM,cAAc,EAAE,OAAO,EAC3B,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,wCAAwC,EACvE,CAAC;AAED,MAAM,eAAe,EAAE,OAAO;CAC5B,QAAQ,EAAE,OAAO;CACjB,QAAQ,EAAE,OAAO;CACjB,UAAU,EAAE,OAAO;AACrB,CAAC;AAMD,SAAS,YACP,QACA,WACA,cAAc,OAAO,QACb;CACR,IAAI,eAAe,WACjB,OAAO;CAMT,OAAO,GADQ,OAAO,MAAM,GAAG,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,EAC1C,EAAE,uBAAuB,cAAc,UAAU;AAClE;;;;;;;;;;;;;;;;AAiBA,eAAsB,eAAe,EACnC,SACA,kBACA,kBAAkB,KAClB,WAUA;CACA,IACE,YAAY,KAAA,MACX,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,KAAK,UAAU,aAExD,MAAM,IAAI,qBAAqB;EAC7B,WAAW;EACX,OAAO;EACP,SAAS;CACX,CAAC;CAGH,IAAI,CAAC,OAAO,cAAc,eAAe,KAAK,kBAAkB,GAC9D,MAAM,IAAI,qBAAqB;EAC7B,WAAW;EACX,OAAO;EACP,SAAS;CACX,CAAC;CAGH,IAAI,qBAAqB,KAAA,KAAa,CAAC,MAAM,WAAW,gBAAgB,GACtE,MAAM,IAAI,qBAAqB;EAC7B,WAAW;EACX,OAAO;EACP,SAAS;CACX,CAAC;CAGH,IAAI,qBAAqB,KAAA,GACvB,mBAAmB,MAAM,UAAU,gBAAgB;CAGrD,IAAI,qBAAqB,KAAA,GAAW;EAClC,MAAM,kBAAkB,MAAM,QAAQ,IAAI,EACxC,SAAS,gBAAgB,iBAAiB,QAAQ,MAAM,OAAO,EAAE,GACnE,CAAC;EACD,IAAI,gBAAgB,aAAa,GAC/B,MAAM,IAAI,MACR,uCAAuC,gBAAgB,QACzD;CAEJ;CAEA,OAAO,KAAgC;EACrC,aACE,wCACC,qBAAqB,KAAA,IAClB,2BAA2B,iBAAiB,MAC5C,+DACJ,sNAGA,QAAQ;EACV;EACA;EACA,SAAS,OAAO,EAAE,WAAW,EAAE,kBAAkB;GAC/C,MAAM,gBACJ,YAAY,KAAA,IAAY,KAAA,IAAY,YAAY,QAAQ,OAAO;GACjE,MAAM,gBACJ,kBAAkB,KAAA,IACd,cACA,gBAAgB,KAAA,IACd,gBACA,YAAY,IAAI,CAAC,aAAa,aAAa,CAAC;GAEpD,MAAM,EAAE,QAAQ,QAAQ,UAAU,cAAc,iBAC9C,MAAM,QAAQ,IAAI;IAChB;IACA,GAAI,qBAAqB,KAAA,IAAY,EAAE,iBAAiB,IAAI,CAAC;IAC7D,aAAa;IACb;GACF,CAAC;GAEH,OAAO;IACL,QAAQ,YAAY,QAAQ,iBAAiB,YAAY;IACzD,QAAQ,YAAY,QAAQ,iBAAiB,YAAY;IACzD;GACF;EACF;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/tool-bash",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Provider-independent bash tool for the AI SDK",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -28,15 +28,15 @@
28
28
  "zod": "4.6.7"
29
29
  },
30
30
  "peerDependencies": {
31
- "ai": "^7.0.176"
31
+ "ai": "^7.0.178"
32
32
  },
33
33
  "devDependencies": {
34
- "@ai-sdk/sandbox-just-bash": "1.0.187",
35
- "@ai-sdk/sandbox-vercel": "1.0.187",
34
+ "@ai-sdk/sandbox-just-bash": "1.0.189",
35
+ "@ai-sdk/sandbox-vercel": "1.0.189",
36
36
  "@types/node": "22.19.19",
37
37
  "@vercel/ai-tsconfig": "0.0.0",
38
38
  "@vercel/ai-tsdown-config": "0.0.0",
39
- "ai": "7.0.176",
39
+ "ai": "7.0.178",
40
40
  "tsdown": "^0.23.0",
41
41
  "typescript": "6.0.3"
42
42
  },
@@ -57,10 +57,9 @@
57
57
  "url": "https://github.com/vercel/ai/issues"
58
58
  },
59
59
  "scripts": {
60
- "build": "pnpm clean && tsdown",
60
+ "build": "tsdown",
61
61
  "build:watch": "tsdown --watch",
62
- "clean": "del-cli *.tsbuildinfo",
63
- "type-check": "tsc --build",
62
+ "type-check": "tsc --noEmit",
64
63
  "test": "pnpm test:node",
65
64
  "test:node": "vitest --config vitest.node.config.js --run",
66
65
  "test:watch": "vitest --config vitest.node.config.js"
package/src/bash-tool.ts CHANGED
@@ -22,12 +22,19 @@ type BashInput = z.infer<typeof inputSchema>;
22
22
 
23
23
  type BashOutput = z.infer<typeof outputSchema>;
24
24
 
25
- function limitOutput(output: string, maxLength: number): string {
26
- if (output.length <= maxLength) {
25
+ function limitOutput(
26
+ output: string,
27
+ maxLength: number,
28
+ totalLength = output.length,
29
+ ): string {
30
+ if (totalLength <= maxLength) {
27
31
  return output;
28
32
  }
29
33
 
30
- return `${output.slice(0, maxLength)}\n[Output truncated: ${output.length - maxLength} characters omitted.]`;
34
+ // Also copy prefixes returned by older or custom sandboxes, which may not
35
+ // support bounded output and can return a substring backed by a large string.
36
+ const prefix = output.slice(0, maxLength).split('').join('');
37
+ return `${prefix}\n[Output truncated: ${totalLength - maxLength} characters omitted.]`;
31
38
  }
32
39
 
33
40
  /**
@@ -124,15 +131,17 @@ export async function createBashTool({
124
131
  ? timeoutSignal
125
132
  : AbortSignal.any([abortSignal, timeoutSignal]);
126
133
 
127
- const { stdout, stderr, exitCode } = await sandbox.run({
128
- command,
129
- ...(workingDirectory !== undefined ? { workingDirectory } : {}),
130
- abortSignal: commandSignal,
131
- });
134
+ const { stdout, stderr, exitCode, stdoutLength, stderrLength } =
135
+ await sandbox.run({
136
+ command,
137
+ ...(workingDirectory !== undefined ? { workingDirectory } : {}),
138
+ abortSignal: commandSignal,
139
+ maxOutputLength,
140
+ });
132
141
 
133
142
  return {
134
- stdout: limitOutput(stdout, maxOutputLength),
135
- stderr: limitOutput(stderr, maxOutputLength),
143
+ stdout: limitOutput(stdout, maxOutputLength, stdoutLength),
144
+ stderr: limitOutput(stderr, maxOutputLength, stderrLength),
136
145
  exitCode,
137
146
  };
138
147
  },