danny-avila/LibreChat · error

Reading "${file_path}" exceeded the sandbox stdout limit (ch

Error message

Reading "${file_path}" exceeded the sandbox stdout limit (chunk ${chunkBytes} bytes). Lower LIBRECHAT_CODE_IMAGE_CHUNK_BYTES or raise SANDBOX_OUTPUT_MAX_SIZE on the runner.

What it means

Thrown by execSandboxImageChunk (Code/process.js) when the sandbox runner reports status 'OL' (Output Limit): the chunk's stdout exceeded SANDBOX_OUTPUT_MAX_SIZE, so the runner truncated it and SIGKILLed the job. The surviving stdout is a base64 string cut mid-flight, so this explicit check names the real cause instead of letting JSON.parse fail with a confusing message.

Source

Thrown at api/server/services/Files/Code/process.js:1397

      method: 'post',
      url: `${baseURL}/exec`,
      data: postData,
      headers: {
        'Content-Type': 'application/json',
        'User-Agent': 'LibreChat/1.0',
        ...authHeaders,
      },
      httpAgent: codeServerHttpAgent,
      httpsAgent: codeServerHttpsAgent,
      timeout: 15000,
    });
    const result = response?.data ?? {};
    /* The runner truncates stdout at SANDBOX_OUTPUT_MAX_SIZE and SIGKILLs the
     * job (status `OL`). Detect that explicitly: the surviving stdout is a
     * base64 string cut mid-flight, so parsing it yields a misleading
     * "unexpected output" instead of naming the real, fixable cause. */
    if (result.status === 'OL') {
      throw new Error(
        `Reading "${file_path}" exceeded the sandbox stdout limit (chunk ${chunkBytes} bytes). ` +
          'Lower LIBRECHAT_CODE_IMAGE_CHUNK_BYTES or raise SANDBOX_OUTPUT_MAX_SIZE on the runner.',
      );
    }
    if (result.stderr && (result.stdout == null || result.stdout === '')) {
      throw new Error(String(result.stderr).trim());
    }
    if (result.stdout == null || String(result.stdout).trim() === '') {
      return {};
    }
    /* Parse the LAST non-empty line: the reader's JSON is the final thing it
     * prints, so anything a shell profile or library emitted ahead of it
     * (banners, warnings) must not break the read. */
    const lines = String(result.stdout)
      .split('\n')
      .map((line) => line.trim())
      .filter(Boolean);
    try {

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Lower LIBRECHAT_CODE_IMAGE_CHUNK_BYTES so a single chunk's base64 fits under SANDBOX_OUTPUT_MAX_SIZE.
  2. Or raise SANDBOX_OUTPUT_MAX_SIZE on the runner to accommodate the current chunk size.
  3. Keep the two settings in a documented ratio (chunk base64 ≈ chunkBytes * 1.37, must be < SANDBOX_OUTPUT_MAX_SIZE).
  4. After changing either, restart both the API server and the sandbox runner.
Defensive patterns

Strategy: validation

Validate before calling

// Keep chunk base64 under the runner cap before reading
const chunkBytes = Number(process.env.LIBRECHAT_CODE_IMAGE_CHUNK_BYTES);
const runnerCap = Number(process.env.SANDBOX_OUTPUT_MAX_SIZE);
if (chunkBytes * 1.37 >= runnerCap) {
  throw new Error('LIBRECHAT_CODE_IMAGE_CHUNK_BYTES too large for SANDBOX_OUTPUT_MAX_SIZE');
}

Try / catch

try {
  const img = await readSandboxImage({ file_path, session_id, req });
} catch (err) {
  if (/exceeded the sandbox stdout limit/.test(err.message)) {
    // operator action: adjust config, not a code retry
    logger.error('Config mismatch — adjust chunk/output caps', { chunkBytes, runnerCap });
  }
  throw err;
}

Prevention

When it happens

Trigger: LIBRECHAT_CODE_IMAGE_CHUNK_BYTES is set large enough that the base64 of a single chunk exceeds the runner's SANDBOX_OUTPUT_MAX_SIZE; SANDBOX_OUTPUT_MAX_SIZE on the runner was lowered; reading a large image with an oversized chunk setting.

Common situations: Operator raised LIBRECHAT_CODE_IMAGE_CHUNK_BYTES to reduce round-trips without proportionally raising SANDBOX_OUTPUT_MAX_SIZE; runner config drifted from the API server config; newly deployed runner with a smaller default cap.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/d31e6473fb364ee5. Report an issue: GitHub.