{"record":{"id":"6c1c1e6810f6a708","repo":"mastra-ai/mastra","slug":"worker-arguments-must-not-contain-nul-bytes","errorCode":null,"errorMessage":"Worker arguments must not contain NUL bytes.","messagePattern":"Worker arguments must not contain NUL bytes\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deployers/sandbox/src/worker.ts","lineNumber":170,"sourceCode":"    sandbox: options.sandbox,\n    resolveRemoteDir: async () => (remoteDir ??= await resolveRemoteDir(options.sandbox, options.remoteDir)),\n    terminationGraceMs: options.terminationGraceMs ?? 5_000,\n  };\n  const info = await getInfoSafe(options.sandbox);\n  return execution(config, options.executionId, info?.id ?? options.sandbox.id, info?.timeoutAt);\n}\n\nfunction validateOptions(options: DeployWorkerToSandboxOptions): void {\n  if (!options.sandbox.executeCommand) {\n    throw new Error(\n      `Sandbox provider \"${options.sandbox.provider}\" does not support executeCommand, which is required for worker deploys.`,\n    );\n  }\n  validateExecutionId(options.executionId);\n  if (!options.command || /[\\0\\r\\n]/.test(options.command)) {\n    throw new Error('Worker command must be a non-empty executable path.');\n  }\n  if (options.args?.some(arg => arg.includes('\\0'))) throw new Error('Worker arguments must not contain NUL bytes.');\n  for (const key of Object.keys(options.env ?? {})) {\n    if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid worker environment variable name: ${key}`);\n  }\n  validateRelativePath(options.workingDirectory ?? '.', 'workingDirectory');\n  validateInput(options.input);\n  for (const [name, value] of [\n    ['inputLimitBytes', options.inputLimitBytes],\n    ['startupTimeoutMs', options.startupTimeoutMs],\n    ['executionTimeoutMs', options.executionTimeoutMs],\n    ['terminationGraceMs', options.terminationGraceMs],\n  ] as const) {\n    if (value !== undefined && (!Number.isFinite(value) || value <= 0))\n      throw new Error(`${name} must be greater than zero.`);\n  }\n  const resourceLimits = options.resourceLimits;\n  if (resourceLimits) {\n    const knownLimits = new Set(['cpuTimeSeconds', 'addressSpaceBytes', 'fileSizeBytes', 'openFiles']);\n    for (const name of Object.keys(resourceLimits)) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/deployers/sandbox/src/worker.ts#L152-L188","documentation":"Worker arguments are forwarded to the provider exec API as an argv array; NUL bytes cannot appear in a real argv entry on POSIX systems, so any arg containing \\0 is rejected during validation.","triggerScenarios":"Passing options.args where at least one string includes the \\0 character.","commonSituations":"Arguments read from binary buffers without UTF-8 sanitization; values sliced from C-style buffers including the terminating NUL; corrupt or malicious config input.","solutions":["Strip or split on NUL bytes before passing args (e.g. arg.replace(/\\0/g, '') or buffer.toString('utf8')).","Ensure args originate from string sources, not raw Buffers with terminator bytes.","Log and inspect the offending arg if the source is untrusted input."],"exampleFix":"// before\nconst args = [buffer.toString('binary')]; // may contain \\0\nawait deployWorkerToSandbox({ sandbox, command: 'node', args });\n// after\nconst args = [buffer.toString('utf8').replace(/\\0/g, '')];\nawait deployWorkerToSandbox({ sandbox, command: 'node', args });","handlingStrategy":"validation","validationCode":"if (args?.some(a => a.includes('\\0'))) throw new Error('Worker arguments must not contain NUL bytes');","typeGuard":"const hasNoNul = (args: unknown): args is string[] =>\n  Array.isArray(args) && args.every(a => typeof a === 'string' && !a.includes('\\0'));","tryCatchPattern":null,"preventionTips":["Convert Buffers with toString('utf8') before using them as args","Strip NULs when args come from external/binary sources","Fuzz your config loader for control characters"],"tags":["worker","validation","argv"],"backgroundTag":"invalid-option-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}