{"record":{"id":"1b73cd2048bd6e58","repo":"infiniflow/ragflow","slug":"ucloud-agent-sandbox-execution-failed-exc","errorCode":null,"errorMessage":"UCloud Agent Sandbox execution failed: {exc}","messagePattern":"UCloud Agent Sandbox execution failed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/providers/ucloud_agent_sandbox.py","lineNumber":210,"sourceCode":"            raise RuntimeError(f\"Execution timeout must be greater than 0 seconds, got {requested_timeout}.\")\n        exec_timeout = min(requested_timeout, self.timeout)\n        sdk = _get_ucloud_sandbox_module()\n\n        start_time = time.time()\n        try:\n            sandbox.set_timeout(max(self.sandbox_timeout, exec_timeout + 30), request_timeout=self.timeout)\n            result = sandbox.commands.run(\n                f\"{executable} {shlex.quote(script_path)}\",\n                cwd=remote_work_dir,\n                timeout=exec_timeout,\n                request_timeout=max(self.timeout, exec_timeout),\n            )\n        except sdk.CommandExitException as exc:\n            result = exc\n        except sdk.TimeoutException as exc:\n            raise TimeoutError(f\"Execution timed out after {exec_timeout} seconds\") from exc\n        except Exception as exc:\n            raise RuntimeError(f\"UCloud Agent Sandbox execution failed: {exc}\") from exc\n        execution_time = time.time() - start_time\n\n        stdout = result.stdout or \"\"\n        stderr = result.stderr or \"\"\n        exit_code = int(result.exit_code)\n        self._validate_output_size(stdout, stderr)\n        stdout, structured_result = extract_structured_result(stdout)\n\n        return ExecutionResult(\n            stdout=stdout,\n            stderr=stderr,\n            exit_code=exit_code,\n            execution_time=execution_time,\n            metadata={\n                \"instance_id\": instance_id,\n                \"sandbox_id\": sandbox.sandbox_id,\n                \"language\": normalized_lang,\n                \"script_path\": script_path,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/ucloud_agent_sandbox.py#L192-L228","documentation":"Generic catch-all around `sandbox.commands.run(...)`: any SDK exception that is not CommandExitException (a normal non-zero exit, which becomes the result) or TimeoutException is re-raised as RuntimeError with the original error chained. Covers transport failures, sandbox died mid-run, set_timeout failures, and unknown SDK error types.","triggerScenarios":"Sandbox VM reclaimed/killed while the command ran; network drop between RAGFlow and UCloud during execution; `sandbox.set_timeout(...)` API failing; SDK raising a novel exception type.","commonSituations":"Long executions outliving the sandbox VM lease; flaky networking to the UCloud gateway; executing after the sandbox was concurrently terminated by another component.","solutions":["Inspect `exc.__cause__` to find the real SDK failure before deciding to retry.","For 'sandbox gone'/transport errors, recreate the instance and re-run the script idempotently.","Keep executions well under sandbox_timeout so the VM is not reclaimed mid-command.","Ensure only one component controls a given instance handle's lifecycle."],"exampleFix":"# before\nresult = provider.execute(inst, code)  # opaque RuntimeError mid-run\n\n# after\ntry:\n    result = provider.execute(inst, code)\nexcept RuntimeError as e:\n    if \"sandbox\" in str(e.__cause__ or \"\").lower():\n        inst = provider.create_instance(\"python\")\n        result = provider.execute(inst, code)\n    else:\n        raise","handlingStrategy":"try-catch","validationCode":"# keep executions short relative to the sandbox lease\nif int(conf.get(\"sandbox_timeout\", 300)) <= int(conf.get(\"timeout\", 30)):\n    conf[\"sandbox_timeout\"] = int(conf.get(\"timeout\", 30)) + 60","typeGuard":"def is_recoverable_exec_error(exc: RuntimeError) -> bool:\n    text = str(exc.__cause__ or exc).lower()\n    return any(t in text for t in (\"connection\", \"not found\", \"gone\", \"terminated\"))","tryCatchPattern":"try:\n    result = provider.execute(inst, code)\nexcept RuntimeError as e:\n    if is_recoverable_exec_error(e):\n        inst = provider.create_instance(\"python\")  # refresh dead sandbox, then rerun idempotent code\n        result = provider.execute(inst, code)\n    else:\n        raise","preventionTips":["Keep command duration well under sandbox_timeout so the VM lease never expires mid-run.","Make executed scripts idempotent so a recreate-and-rerun recovery is safe.","Log e.__cause__ to separate transport failures from genuine code failures."],"tags":["execution","ucloud","sandbox","network","catch-all"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}