mastra-ai/mastra · error

Worker input exceeds inputLimitBytes (${data.byteLength} > $

Error message

Worker input exceeds inputLimitBytes (${data.byteLength} > ${config.inputLimitBytes}).

What it means

stageInput uploads worker input into the sandbox but enforces a configured maximum input size (config.inputLimitBytes). If the serialized input buffer is larger than that limit, the library throws before any upload, since oversized payloads could exhaust sandbox memory/disk or break the transport.

Source

Thrown at deployers/sandbox/src/worker.ts:428

  return {
    ...execution(config, executionId, sandboxId, expiresAt),
    relaunch: async options => {
      if (options.executionId === executionId) throw new Error('Relaunch requires a new executionId.');
      validateInput(options.input);
      return createExecution(config, options.executionId, options.input);
    },
  };
}

async function stageInput(
  config: WorkerConfig,
  paths: ReturnType<typeof executionPaths>,
  input?: SandboxWorkerInput,
): Promise<string | undefined> {
  if (!input) return undefined;
  const data = typeof input.data === 'string' ? Buffer.from(input.data) : Buffer.from(input.data);
  if (data.byteLength > config.inputLimitBytes) {
    throw new Error(`Worker input exceeds inputLimitBytes (${data.byteLength} > ${config.inputLimitBytes}).`);
  }
  const path = input.type === 'stdin' ? paths.stdin : posix.resolve(config.remoteDir, input.path);
  await uploadFile(config.sandbox, path, data);
  await runInSandbox(config.sandbox, `chmod 600 ${shellQuote(path)}`);
  return input.type === 'stdin' ? path : undefined;
}

function buildExecutionScript(
  config: WorkerConfig,
  paths: ReturnType<typeof executionPaths>,
  stdinPath?: string,
): string {
  const cwd = posix.resolve(config.remoteDir, config.workingDirectory);
  const envPrefix = Object.entries(config.env)
    .map(([key, value]) => `${key}=${shellQuote(value)}`)
    .join(' ');
  const executable = [shellQuote(config.command), ...config.args.map(shellQuote)].join(' ');
  const target = `${envPrefix ? `env ${envPrefix} ` : ''}${executable}`;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Increase config.inputLimitBytes to accommodate your payload size.
  2. Split the input into chunks and pass a reference (e.g. an object-store key or path) instead of inlining the data.
  3. Compress the payload before staging and decompress inside the worker.
  4. Trim the input to only the data the worker actually needs.

Example fix

// before
await worker.run({ input: { type: 'stdin', data: bigJsonString } });
// after
if (Buffer.byteLength(bigJsonString) > inputLimitBytes) {
  await uploadToStore(key, bigJsonString);
  await worker.run({ input: { type: 'stdin', data: JSON.stringify({ ref: key }) } });
}
Defensive patterns

Strategy: validation

Validate before calling

function assertInputWithinLimit(input, inputLimitBytes) {
  const bytes = Buffer.byteLength(typeof input === 'string' ? input : input.data);
  if (bytes > inputLimitBytes) throw new Error(`input ${bytes}B exceeds limit ${inputLimitBytes}B`);
}

Type guard

function inputFitsLimit(input, limit) {
  if (!input) return true;
  const data = input.data;
  const size = typeof data === 'string' ? Buffer.byteLength(data) : data?.byteLength ?? 0;
  return size <= limit;
}

Try / catch

try {
  await worker.run({ input });
} catch (e) {
  if (/exceeds inputLimitBytes/.test(e.message)) {
    // offload to external storage and pass a reference instead
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the worker deployment with input whose Buffer/string byteLength exceeds inputLimitBytes — via the stdinPath/stageInput path when preparing stdin input or a staged input file.

Common situations: Passing large JSON payloads, embeddings, or file blobs as worker input; inputLimitBytes configured too small for the workload; double-encoded (base64) input inflating byte size; forgetting to chunk large inputs.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/770f09923b9bcc2e. Report an issue: GitHub.