{"record":{"id":"60af663073b4df3f","repo":"infiniflow/ragflow","slug":"execution-timed-out-after-exec-timeout-seconds-60af66","errorCode":null,"errorMessage":"Execution timed out after {exec_timeout} seconds","messagePattern":"Execution timed out after (.+?) seconds","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"warning","filePath":"agent/sandbox/providers/tenki.py","lineNumber":217,"sourceCode":"        instance = self._instances[instance_id]\n        sandbox = instance[\"sandbox\"]\n        remote_work_dir: str = instance[\"remote_work_dir\"]\n        errors = self._tenki_errors()\n\n        args_json = json.dumps(arguments or {}, ensure_ascii=False)\n        script_path, argv = self._prepare_script(sandbox, remote_work_dir, normalized_lang, code, args_json)\n\n        requested_timeout = self.timeout if timeout is None else int(timeout)\n        if requested_timeout <= 0:\n            raise RuntimeError(f\"Execution timeout must be greater than 0 seconds, got {requested_timeout}.\")\n        exec_timeout = min(requested_timeout, self.timeout)\n\n        start_time = time.time()\n        try:\n            result = sandbox.exec(*argv, cwd=remote_work_dir, timeout=exec_timeout)\n        except (errors.CommandTimeoutError, errors.PrimitiveTimeoutError) as exc:\n            logger.warning(\"Tenki execution timed out (instance=%s, timeout=%ss)\", instance_id, exec_timeout)\n            raise TimeoutError(f\"Execution timed out after {exec_timeout} seconds\") from exc\n        except (errors.SessionTerminatedError, errors.SessionNotFoundError) as exc:\n            # The sandbox was reclaimed (e.g. max_lifetime) or lost mid-run;\n            # surface it as RuntimeError per the base contract, not an SDK type.\n            raise RuntimeError(f\"Tenki sandbox is no longer available: {exc}\") from exc\n        except Exception as exc:\n            raise RuntimeError(f\"Tenki execution failed: {exc}\") from exc\n        execution_time = time.time() - start_time\n\n        stdout = result.stdout_text\n        stderr = result.stderr_text\n        exit_code = int(result.exit_code)\n\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,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/tenki.py#L199-L235","documentation":"TimeoutError raised when sandbox.exec() throws errors.CommandTimeoutError or errors.PrimitiveTimeoutError: the user script did not finish within exec_timeout, which is min(requested_timeout, self.timeout). The provider logs a warning with the instance id and effective timeout before raising.","triggerScenarios":"Running code that loops forever, sleeps, or is simply slower than the timeout — e.g. default 30s config with a 60s computation; or requesting a larger timeout than the provider config, which gets clamped down to self.timeout.","commonSituations":"LLM-generated code with infinite loops or long sleeps; forgetting that the per-call timeout can never exceed the provider-level timeout set in initialize(); heavy data processing inside the sandbox.","solutions":["Raise timeout in the initialize() config (per-call values are clamped to it) and pass an explicit per-call timeout.","Fix or bound the generated script: add iteration limits, avoid sleep loops, stream results in chunks.","Treat TimeoutError separately from RuntimeError in callers — the sandbox survives a command timeout, so retrying with a shorter/cheaper script on the same instance is safe."],"exampleFix":"# before\nprovider.initialize({\"api_key\": key, \"timeout\": 30})\nprovider.execute_code(inst, slow_code, timeout=120)  # silently clamped to 30\n\n# after\nprovider.initialize({\"api_key\": key, \"timeout\": 120})\nprovider.execute_code(inst, slow_code, timeout=120)","handlingStrategy":"retry","validationCode":"effective = provider.timeout if timeout is None else min(int(timeout), provider.timeout)\nif effective < estimated_runtime_seconds:\n    logger.warning(\"script may exceed tenki timeout of %ss\", effective)","typeGuard":null,"tryCatchPattern":"try:\n    result = provider.execute_code(instance_id, code, timeout=t)\nexcept TimeoutError:\n    # sandbox survives; retry cheaper/bounded script on the same instance\n    result = provider.execute_code(instance_id, bounded_code, timeout=t)","preventionTips":["Set provider-level timeout in initialize() to your worst-case script duration; per-call values are clamped to it.","Generate scripts with iteration caps and no unbounded sleeps.","Catch TimeoutError separately from RuntimeError — only the former implies the sandbox is still usable."],"tags":["timeout","execution","sandbox","tenki"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}