{"record":{"id":"9f7d807b49142bcf","repo":"infiniflow/ragflow","slug":"ucloud-agent-sandbox-execution-output-exceeded-se","errorCode":null,"errorMessage":"UCloud Agent Sandbox execution output exceeded {self.max_output_bytes} bytes.","messagePattern":"UCloud Agent Sandbox execution output exceeded (.+?) bytes\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/providers/ucloud_agent_sandbox.py","lineNumber":405,"sourceCode":"        if language == \"python\":\n            script_name = \"main.py\"\n            script_content = build_python_wrapper(code, args_json)\n            executable = \"python3\"\n        elif language == \"nodejs\":\n            script_name = \"main.js\"\n            script_content = build_javascript_wrapper(code, args_json)\n            executable = \"node\"\n        else:\n            raise RuntimeError(f\"Unsupported language for UCloud Agent Sandbox provider: {language}\")\n        script_path = posixpath.join(remote_work_dir, script_name)\n        sandbox.files.write(script_path, script_content, request_timeout=self.timeout)\n        return script_path, executable\n\n    def _validate_output_size(self, stdout: str, stderr: str) -> None:\n        \"\"\"Reject combined standard output that exceeds the configured limit.\"\"\"\n        output_size = len(stdout.encode(\"utf-8\")) + len(stderr.encode(\"utf-8\"))\n        if output_size > self.max_output_bytes:\n            raise RuntimeError(f\"UCloud Agent Sandbox execution output exceeded {self.max_output_bytes} bytes.\")\n\n    def _collect_artifacts(self, sandbox, artifacts_dir: str) -> list[dict[str, Any]]:\n        \"\"\"Collect allowed files from the execution artifact directory.\"\"\"\n        artifacts: list[dict[str, Any]] = []\n        self._collect_artifacts_recursive(sandbox, artifacts_dir, \"\", artifacts, depth=0)\n        return artifacts\n\n    def _collect_artifacts_recursive(self, sandbox, current_dir: str, relative_dir: str, artifacts: list[dict[str, Any]], depth: int) -> None:\n        \"\"\"Traverse artifact directories while enforcing type, size, and depth limits.\"\"\"\n        if depth > MAX_ARTIFACT_DEPTH:\n            raise RuntimeError(f\"Artifact directory nesting exceeds {MAX_ARTIFACT_DEPTH} levels: {relative_dir}\")\n        sdk = _get_ucloud_sandbox_module()\n        try:\n            entries = sandbox.files.list(current_dir, depth=1, request_timeout=self.timeout)\n        except sdk.FileNotFoundException:\n            return\n        for entry in sorted(entries, key=lambda item: item.path):\n            name = posixpath.basename(entry.path)","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/ucloud_agent_sandbox.py#L387-L423","documentation":"Raised after a command completes if the UTF-8 byte size of stdout plus stderr exceeds `max_output_bytes` (default 1 MiB). The check runs before structured-result extraction, so oversized output aborts the whole execution result even though the process finished.","triggerScenarios":"User code printing large dumps: full dataset prints, base64 blobs, verbose logs, or unbounded iteration output — combined stdout+stderr over the configured cap.","commonSituations":"LLM-generated code that prints an entire DataFrame or file contents; debug prints left in scripts; default 1 MiB too small for legitimate outputs like generated reports.","solutions":["Reduce the script's output (print summaries, slice results, write large data to the artifacts dir instead of stdout).","Raise `max_output_bytes` in the provider config if larger outputs are legitimate.","Stream/redirect heavy output to a file in the artifacts directory, which has its own size/type policy.","Catch RuntimeError at the call site and degrade to a 'output too large' message for the agent."],"exampleFix":"# before\nprint(open('big.json').read())  # >1MiB stdout -> RuntimeError\n\n# after\nopen('artifacts/report.json', 'w').write(open('big.json').read())\nprint('report written')","handlingStrategy":"try-catch","validationCode":"limit = int(conf.get(\"max_output_bytes\", 1024 * 1024))\n# budget the code you send: instruct/generate scripts that print bounded output\nsafe_code = code.replace(\"print(df)\", \"print(df.head(50))\")  # example narrowing","typeGuard":"def is_output_size_error(exc: RuntimeError) -> bool:\n    return \"output exceeded\" in str(exc)","tryCatchPattern":"try:\n    result = provider.execute(inst, code)\nexcept RuntimeError as e:\n    if \"output exceeded\" in str(e):\n        result = ExecutionResult(stdout=\"\", stderr=\"output too large; write results to artifacts instead\", exit_code=1)\n    else:\n        raise","preventionTips":["Print summaries (head/slice/counts), never full datasets or file bodies.","Raise max_output_bytes in config only when legitimate, and pair it with artifact policies for big data.","Route large results through the artifacts directory, not stdout."],"tags":["output-limit","ucloud","sandbox","stdout","resource-limits"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}