{"record":{"id":"765754447c0be3fc","repo":"BerriAI/litellm","slug":"sandbox-output-exceeded-sandbox-max-output-bytes","errorCode":null,"errorMessage":"Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; aborting to avoid unbounded memory use.","messagePattern":"Sandbox output exceeded (.+?) bytes; aborting to avoid unbounded memory use\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/base_llm/sandbox/transformation.py","lineNumber":88,"sourceCode":"    ) -> CodeExecutionResult:\n        raise NotImplementedError(\"arun_code must be implemented by provider\")\n\n    async def adelete_sandbox(\n        self,\n        *,\n        container: ContainerHandle | str,\n        api_key: str | None = None,\n        **kwargs,\n    ) -> bool:\n        raise NotImplementedError(\"adelete_sandbox must be implemented by provider\")\n\n    async def _read_capped_lines(self, response: httpx.Response) -> list[str]:\n        lines: Final[list[str]] = []\n        total = 0\n        async for line in response.aiter_lines():\n            total += len(line.encode(\"utf-8\"))\n            if total > SANDBOX_MAX_OUTPUT_BYTES:\n                raise ValueError(\n                    f\"Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; aborting to avoid unbounded memory use.\"\n                )\n            lines.append(line)\n        return lines\n","sourceCodeStart":70,"sourceCodeEnd":93,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/sandbox/transformation.py#L70-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","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).","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.","For untrusted code, pre-scan or wrap execution with a print limiter before it reaches the 10 MiB cap."],"exampleFix":"# before (code executed in sandbox)\nprint(huge_df)            # >10 MiB of output -> ValueError\n\n# after\nhuge_df.to_csv(\"out.csv\")  # large output goes to a file\nprint(huge_df.head())      # small summary to stdout","handlingStrategy":"validation","validationCode":"# sandbox-side: cap output before it reaches litellm's 10 MiB limit\nMAX_PRINT = 1_000_000\ncode = f\"\"\"\nimport sys, functools\nprint = functools.partial(_capped_print, print, max_bytes={MAX_PRINT})\n\"\"\" + user_code","typeGuard":"def is_sandbox_output_limit_error(e: BaseException) -> bool:\n    return isinstance(e, ValueError) and e.args and \"Sandbox output exceeded\" in str(e.args[0])","tryCatchPattern":"try:\n    result = await sandbox.arun_code(container=h, code=src)\nexcept ValueError as e:\n    if \"Sandbox output exceeded\" in str(e):\n        result = await sandbox.arun_code(container=h, code=wrap_output_to_file(src))\n    else:\n        raise","preventionTips":["Never print large objects from sandboxed code; write files and print paths/sizes instead.","Lint generated/executed code for bare print of big structures (df, json.dumps of large payloads).","Treat the 10 MiB cap as a hard contract when designing agent tool output."],"tags":["sandbox","output-limit","memory-safety","value-error","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}