infiniflow/ragflow · error · RuntimeError

UCloud Agent Sandbox execution output exceeded {self.max_out

Error message

UCloud Agent Sandbox execution output exceeded {self.max_output_bytes} bytes.

What it means

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.

Source

Thrown at agent/sandbox/providers/ucloud_agent_sandbox.py:405

        if language == "python":
            script_name = "main.py"
            script_content = build_python_wrapper(code, args_json)
            executable = "python3"
        elif language == "nodejs":
            script_name = "main.js"
            script_content = build_javascript_wrapper(code, args_json)
            executable = "node"
        else:
            raise RuntimeError(f"Unsupported language for UCloud Agent Sandbox provider: {language}")
        script_path = posixpath.join(remote_work_dir, script_name)
        sandbox.files.write(script_path, script_content, request_timeout=self.timeout)
        return script_path, executable

    def _validate_output_size(self, stdout: str, stderr: str) -> None:
        """Reject combined standard output that exceeds the configured limit."""
        output_size = len(stdout.encode("utf-8")) + len(stderr.encode("utf-8"))
        if output_size > self.max_output_bytes:
            raise RuntimeError(f"UCloud Agent Sandbox execution output exceeded {self.max_output_bytes} bytes.")

    def _collect_artifacts(self, sandbox, artifacts_dir: str) -> list[dict[str, Any]]:
        """Collect allowed files from the execution artifact directory."""
        artifacts: list[dict[str, Any]] = []
        self._collect_artifacts_recursive(sandbox, artifacts_dir, "", artifacts, depth=0)
        return artifacts

    def _collect_artifacts_recursive(self, sandbox, current_dir: str, relative_dir: str, artifacts: list[dict[str, Any]], depth: int) -> None:
        """Traverse artifact directories while enforcing type, size, and depth limits."""
        if depth > MAX_ARTIFACT_DEPTH:
            raise RuntimeError(f"Artifact directory nesting exceeds {MAX_ARTIFACT_DEPTH} levels: {relative_dir}")
        sdk = _get_ucloud_sandbox_module()
        try:
            entries = sandbox.files.list(current_dir, depth=1, request_timeout=self.timeout)
        except sdk.FileNotFoundException:
            return
        for entry in sorted(entries, key=lambda item: item.path):
            name = posixpath.basename(entry.path)

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Reduce the script's output (print summaries, slice results, write large data to the artifacts dir instead of stdout).
  2. Raise `max_output_bytes` in the provider config if larger outputs are legitimate.
  3. Stream/redirect heavy output to a file in the artifacts directory, which has its own size/type policy.
  4. Catch RuntimeError at the call site and degrade to a 'output too large' message for the agent.

Example fix

# before
print(open('big.json').read())  # >1MiB stdout -> RuntimeError

# after
open('artifacts/report.json', 'w').write(open('big.json').read())
print('report written')
Defensive patterns

Strategy: try-catch

Validate before calling

limit = int(conf.get("max_output_bytes", 1024 * 1024))
# budget the code you send: instruct/generate scripts that print bounded output
safe_code = code.replace("print(df)", "print(df.head(50))")  # example narrowing

Type guard

def is_output_size_error(exc: RuntimeError) -> bool:
    return "output exceeded" in str(exc)

Try / catch

try:
    result = provider.execute(inst, code)
except RuntimeError as e:
    if "output exceeded" in str(e):
        result = ExecutionResult(stdout="", stderr="output too large; write results to artifacts instead", exit_code=1)
    else:
        raise

Prevention

When it happens

Trigger: User code printing large dumps: full dataset prints, base64 blobs, verbose logs, or unbounded iteration output — combined stdout+stderr over the configured cap.

Common situations: 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.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/9f7d807b49142bcf. Report an issue: GitHub.