{"record":{"id":"8300705032101a1b","repo":"FoundationAgents/OpenManus","slug":"command-execution-timed-out-after-timeout-second","errorCode":null,"errorMessage":"Command execution timed out after {timeout} seconds","messagePattern":"Command execution timed out after (.+?) seconds","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"app/sandbox/core/terminal.py","lineNumber":214,"sourceCode":"                        if e.errno == socket.EWOULDBLOCK:\n                            await asyncio.sleep(0.1)\n                            continue\n                        raise\n\n                output = b\"\\n\".join(result_lines).decode(\"utf-8\")\n                output = re.sub(r\"\\n\\$ echo \\$\\$?.*$\", \"\", output)\n\n                return output\n\n            if timeout:\n                result = await asyncio.wait_for(read_output(), timeout)\n            else:\n                result = await read_output()\n\n            return result.strip()\n\n        except asyncio.TimeoutError:\n            raise TimeoutError(f\"Command execution timed out after {timeout} seconds\")\n        except Exception as e:\n            raise RuntimeError(f\"Failed to execute command: {e}\")\n\n    def _sanitize_command(self, command: str) -> str:\n        \"\"\"Sanitizes the command string to prevent shell injection.\n\n        Args:\n            command: Raw command string.\n\n        Returns:\n            Sanitized command string.\n\n        Raises:\n            ValueError: If command contains potentially dangerous patterns.\n        \"\"\"\n\n        # Additional checks for specific risky commands\n        risky_commands = [","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/sandbox/core/terminal.py#L196-L232","documentation":"execute() wraps its read loop in asyncio.wait_for(timeout); if the terminal does not return to a shell prompt within the given seconds, asyncio.TimeoutError is converted to a built-in TimeoutError with this message. The read loop only finishes when the '$ ' prompt marker reappears after the echoed exit-code line, so any command that never returns to the prompt will trip it.","triggerScenarios":"Running blocking or interactive commands: servers (python -m http.server), watchers (tail -f), REPLs (python with no args), commands reading stdin (grep with no file), or simply a command that takes longer than the configured timeout (large pip/npm install).","commonSituations":"Default timeout too small for heavyweight installs; agent runs 'npm install' or 'apt-get update' with the default limit; command spawns a background process that inherits stdout and keeps the pipe from showing a clean prompt.","solutions":["Pass a larger timeout for known-slow commands: await term.execute('npm install', timeout=600).","Never launch interactive/daemon processes through this API — background them with nohup and redirect output: 'nohup server > /tmp/log 2>&1 &'.","Close stdin for pipe-hungry commands by appending '< /dev/null'.","Catch TimeoutError in the caller and decide: retry with a bigger budget, or kill the runaway process in the container."],"exampleFix":"# before\nout = await term.execute(\"pip install -r requirements.txt\")\n\n# after\nout = await term.execute(\"pip install -r requirements.txt < /dev/null\", timeout=600)\n# servers/watchers must be detached instead:\nout = await term.execute(\"nohup python -m http.server 8000 > /tmp/http.log 2>&1 &\")","handlingStrategy":"try-catch","validationCode":"BLOCKING = ('http.server', 'tail -f', 'npm start', 'runserver', 'top', 'mysql ')\nif any(b in cmd for b in BLOCKING):\n    cmd = f'nohup {cmd} > /tmp/cmd.log 2>&1 < /dev/null &'\ntimeout = timeout or default_timeout","typeGuard":null,"tryCatchPattern":"try:\n    out = await term.execute(cmd, timeout=120)\nexcept TimeoutError as e:\n    await term.execute('pkill -f \"<pattern-of-cmd>\" || true', timeout=10)\n    out = await term.execute(cmd, timeout=600)  # bigger budget; session may need re-init (see error 46)","preventionTips":["Size timeouts per command class (installs 600s, tests 300s, misc 60s).","Detach servers and watchers with nohup + redirection.","Append '< /dev/null' to commands that might read stdin."],"tags":["timeout","terminal","asyncio","docker"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}