{"record":{"id":"ee4b0f0da0d1fddf","repo":"infiniflow/ragflow","slug":"execution-timed-out-after-timeout-seconds","errorCode":null,"errorMessage":"Execution timed out after {timeout} seconds","messagePattern":"Execution timed out after (.+?) seconds","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/providers/aliyun_codeinterpreter.py","lineNumber":308,"sourceCode":"            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                    \"language\": normalized_lang,\n                    \"context_id\": result.get(\"contextId\") if isinstance(result, dict) else None,\n                    \"timeout\": timeout,\n                    \"result_present\": structured_result.get(\"present\", False),\n                    \"result_value\": structured_result.get(\"value\"),\n                    \"result_type\": structured_result.get(\"type\"),\n                },\n            )\n\n        except ServerError as e:\n            if \"timeout\" in str(e).lower():\n                raise TimeoutError(f\"Execution timed out after {timeout} seconds\")\n            raise RuntimeError(f\"Failed to execute code: {str(e)}\")\n        except Exception as e:\n            raise RuntimeError(f\"Unexpected error during execution: {str(e)}\")\n\n    def destroy_instance(self, instance_id: str) -> bool:\n        \"\"\"\n        Destroy an Aliyun Code Interpreter instance.\n\n        Args:\n            instance_id: ID of the instance to destroy\n\n        Returns:\n            True if destruction successful, False otherwise\n        \"\"\"\n        if not self._initialized or not self._config:\n            raise RuntimeError(\"Provider not initialized. Call initialize() first.\")\n\n        try:","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/aliyun_codeinterpreter.py#L290-L326","documentation":"Raised as TimeoutError when the Aliyun Code Interpreter returns a ServerError whose text contains 'timeout', after the provider enforced its 30-second hard cap (timeout = min(timeout, 30)). It means the sandboxed code did not finish within the allowed window on the Aliyun side.","triggerScenarios":"Executing code that blocks (sleep, long loop, big computation) past the effective timeout; requesting timeout>30 which gets clamped to 30 and then exceeded; slow imports/cold starts inside the sandbox consuming the whole budget.","commonSituations":"Porting code from the self-managed provider (which allows longer timeouts) to Aliyun's 30s cap; heavy data processing in a notebook-style cell; network calls inside sandboxed code without their own timeouts.","solutions":["Reduce the work per execute_code call — split the code so each cell finishes well under 30s.","Set explicit lower timeouts on any network/IO performed inside the sandbox code.","Preload heavy imports at instance creation time so execution cells stay fast.","Treat 30s as a hard platform limit: no configuration raises it."],"exampleFix":"# before\nresult = provider.execute_code(instance_id, slow_code, \"python\", timeout=120)  # clamped to 30, then times out\n\n# after: chunk the work into sub-30s cells\nfor chunk in split_work(slow_code, budget_s=25):\n    result = provider.execute_code(instance_id, chunk, \"python\", timeout=25)","handlingStrategy":"try-catch","validationCode":"# Reject workloads that cannot fit the platform's 30s cap before paying for a call\nEFFECTIVE_CAP = 30\nif estimated_workload_seconds is not None and estimated_workload_seconds > EFFECTIVE_CAP - 5:\n    raise ValueError(\"Workload cannot finish within the Aliyun 30s execution cap; split it\")","typeGuard":null,"tryCatchPattern":"try:\n    result = provider.execute_code(instance_id, code, \"python\", timeout=30)\nexcept TimeoutError:\n    # partial state may exist in the sandbox context; re-run a smaller cell\n    result = provider.execute_code(instance_id, reduced_code, \"python\", timeout=25)","preventionTips":["Design each execution cell to finish in well under 30 seconds.","Add explicit timeouts to any network/IO inside sandboxed code.","Remember the requested timeout is clamped: min(timeout, 30).","Cache heavy imports at instance creation, not per execution."],"tags":["timeout","aliyun","execution","limits"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}