{"record":{"id":"8106860f61553a49","repo":"mastra-ai/mastra","slug":"worker-resourcelimits-name-must-be-a-positive-s","errorCode":null,"errorMessage":"Worker resourceLimits.${name} must be a positive safe integer.","messagePattern":"Worker resourceLimits\\.(.+?) must be a positive safe integer\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deployers/sandbox/src/worker.ts","lineNumber":198,"sourceCode":"    ['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)) {\n      if (!knownLimits.has(name)) throw new Error(`Unknown worker resource limit: ${name}.`);\n    }\n    for (const [name, value] of [\n      ['cpuTimeSeconds', resourceLimits.cpuTimeSeconds],\n      ['addressSpaceBytes', resourceLimits.addressSpaceBytes],\n      ['fileSizeBytes', resourceLimits.fileSizeBytes],\n      ['openFiles', resourceLimits.openFiles],\n    ] as const) {\n      if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {\n        throw new Error(`Worker resourceLimits.${name} must be a positive safe integer.`);\n      }\n    }\n  }\n}\n\nfunction validateRelativePath(value: string, label: string): void {\n  if (!value || posix.isAbsolute(value) || posix.normalize(value).startsWith('..')) {\n    throw new Error(`Worker ${label} must stay within the deployed artifact root.`);\n  }\n}\n\nfunction validateInput(input: SandboxWorkerInput | undefined): void {\n  if (input?.type === 'file') validateRelativePath(input.path, 'input file path');\n}\n\nfunction normalizeResourceLimits(\n  limits: SandboxWorkerResourceLimits | undefined,\n): NormalizedResourceLimits | undefined {","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/deployers/sandbox/src/worker.ts#L180-L216","documentation":"Each provided worker resource limit value must be a positive JavaScript safe integer (Number.isSafeInteger and > 0). validateOptions rejects values that are floats, zero, negative, NaN, Infinity, or beyond Number.MAX_SAFE_INTEGER, because they become ulimit arguments in the sandbox shell and must map to exact integer kernel limits.","triggerScenarios":"Passing resourceLimits.cpuTimeSeconds: 1.5, openFiles: 0, addressSpaceBytes: -1024, fileSizeBytes: Number.MAX_SAFE_INTEGER + 1, or a string/NaN value (e.g. parsed from env as '30s' without conversion) in options.resourceLimits of deployWorkerToSandbox.","commonSituations":"Parsing limits from environment variables or CLI flags without Number() conversion; computing bytes with float math (e.g. 0.5 * 1024 ** 3); passing human strings like '512mb'; copying seconds-based values into byte fields producing tiny/fractional numbers; JSON config with null or 0 defaults.","solutions":["Round the value to a positive safe integer: Math.max(1, Math.floor(value)) and verify Number.isSafeInteger.","Convert human-readable units to whole bytes/seconds yourself (e.g. '512mb' -> 512 * 1024 * 1024).","Remove the key entirely if you don't want to enforce that limit (undefined values are skipped by validation).","Parse env/config inputs with strict validation before constructing the options object."],"exampleFix":"// before\nconst limits = { cpuTimeSeconds: process.env.CPU_SECONDS, fileSizeBytes: 0.5 * 1024 ** 3 };\nawait deployWorkerToSandbox({ sandbox, command: 'node', resourceLimits: limits });\n// after\nconst cpu = Number(process.env.CPU_SECONDS);\nconst limits = {\n  ...(Number.isSafeInteger(cpu) && cpu > 0 ? { cpuTimeSeconds: cpu } : {}),\n  fileSizeBytes: Math.floor(0.5 * 1024 ** 3),\n};\nawait deployWorkerToSandbox({ sandbox, command: 'node', resourceLimits: limits });","handlingStrategy":"validation","validationCode":"function assertPositiveSafeIntLimits(limits) {\n  for (const [name, value] of Object.entries(limits ?? {})) {\n    if (value === undefined) continue;\n    if (!Number.isSafeInteger(value) || value <= 0) {\n      throw new Error(`resourceLimits.${name} must be a positive safe integer, got: ${String(value)}`);\n    }\n  }\n}\nassertPositiveSafeIntLimits(options.resourceLimits);","typeGuard":"function isPositiveSafeInteger(v) {\n  return Number.isSafeInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await deployWorkerToSandbox(options);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('must be a positive safe integer')) {\n    const field = error.message.match(/resourceLimits\\.(\\w+)/)?.[1];\n    console.error(`Fix resourceLimits.${field}: coerce with Math.floor(Number(x)) and ensure > 0`);\n  } else throw error;\n}","preventionTips":["Always derive limits with Math.floor/Math.round from parsed values, never pass raw env strings.","Prefer undefined (omit the key) over 0 or null when a limit is unset.","Guard byte conversions (MB/GB) with Math.floor to avoid float results.","Add a schema (zod/valibot) validation for deploy options parsed from config files."],"tags":["validation","types","worker","sandbox"],"backgroundTag":"invalid-option-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}