BerriAI/litellm · error · ValueError

Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; ab

Error message

Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; aborting to avoid unbounded memory use.

What it means

A hard safety limit in BaseSandboxConfig._read_capped_lines(): while streaming a sandbox code-execution response, LiteLLM accumulates lines and aborts with ValueError if the total output exceeds SANDBOX_MAX_OUTPUT_BYTES (10 MiB, defined at litellm/llms/base_llm/sandbox/transformation.py:16). This prevents a runaway `while True: print(...)` style program from exhausting the proxy's memory. The exception aborts the whole read; partial output is discarded.

Source

Thrown at litellm/llms/base_llm/sandbox/transformation.py:88

    ) -> CodeExecutionResult:
        raise NotImplementedError("arun_code must be implemented by provider")

    async def adelete_sandbox(
        self,
        *,
        container: ContainerHandle | str,
        api_key: str | None = None,
        **kwargs,
    ) -> bool:
        raise NotImplementedError("adelete_sandbox must be implemented by provider")

    async def _read_capped_lines(self, response: httpx.Response) -> list[str]:
        lines: Final[list[str]] = []
        total = 0
        async for line in response.aiter_lines():
            total += len(line.encode("utf-8"))
            if total > SANDBOX_MAX_OUTPUT_BYTES:
                raise ValueError(
                    f"Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; aborting to avoid unbounded memory use."
                )
            lines.append(line)
        return lines

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Change the executed code to bound its output: print summaries/slices (df.head()), write large data to a file or object store instead of stdout, and avoid unbounded loops.
  2. Catch the ValueError in the caller and treat it as 'output too large' — rerun the job with output redirection (e.g. `python job.py > out.txt` and print only tail/head).
  3. If you control the deployment and truly need more, the constant is a module-level Final (SANDBOX_MAX_OUTPUT_BYTES); patching it is possible but not a supported knob — prefer fixing the payload.
  4. For untrusted code, pre-scan or wrap execution with a print limiter before it reaches the 10 MiB cap.

Example fix

# before (code executed in sandbox)
print(huge_df)            # >10 MiB of output -> ValueError

# after
huge_df.to_csv("out.csv")  # large output goes to a file
print(huge_df.head())      # small summary to stdout
Defensive patterns

Strategy: validation

Validate before calling

# sandbox-side: cap output before it reaches litellm's 10 MiB limit
MAX_PRINT = 1_000_000
code = f"""
import sys, functools
print = functools.partial(_capped_print, print, max_bytes={MAX_PRINT})
""" + user_code

Type guard

def is_sandbox_output_limit_error(e: BaseException) -> bool:
    return isinstance(e, ValueError) and e.args and "Sandbox output exceeded" in str(e.args[0])

Try / catch

try:
    result = await sandbox.arun_code(container=h, code=src)
except ValueError as e:
    if "Sandbox output exceeded" in str(e):
        result = await sandbox.arun_code(container=h, code=wrap_output_to_file(src))
    else:
        raise

Prevention

When it happens

Trigger: Executed code inside a sandbox producing more than 10 MiB of stdout/stderr (e.g. printing a huge DataFrame, dumping a large file, an infinite print loop) while litellm streams the response line by line.

Common situations: Data-science workflows that print entire datasets; unbounded loops in user-submitted code; logging JSON blobs; a code-generation agent whose generated program prints excessively.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/765754447c0be3fc. Report an issue: GitHub.