{"record":{"id":"ca2344cdba888fed","repo":"FoundationAgents/OpenManus","slug":"failed-to-execute-command-e","errorCode":null,"errorMessage":"Failed to execute command: {e}","messagePattern":"Failed to execute command: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"app/sandbox/core/terminal.py","lineNumber":216,"sourceCode":"                            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 = [\n            \"rm -rf /\",\n            \"rm -rf /*\",","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/sandbox/core/terminal.py#L198-L234","documentation":"Catch-all RuntimeError from DockerSession.execute() for any failure other than timeout: socket.sendall() hitting a broken pipe, the read loop raising, or the connection to the container's exec socket dying. The underlying exception text is embedded, so '{e}' distinguishes a dead container from a dead socket from a parsing bug in the read loop.","triggerScenarios":"Container exited or was killed between create() and execute() (sendall raises BrokenPipeError/OSError); docker daemon restarted; the session was closed by another task; the prompt-marker regex failed on exotic command output and the reader raised.","commonSituations":"Long-lived agent sessions where the sandbox container hit its TTL; OOM-kill of the container mid-command; concurrent code paths closing the terminal while a command is in flight.","solutions":["Inspect '{e}' — BrokenPipeError/OSError means the container side is gone; recreate the container and session.","Check container state before retrying: docker inspect or container.reload() + container.status == 'running'.","Serialize access to one session (a lock or single-owner task) so close() cannot race execute().","Build session recovery into the caller: on RuntimeError containing 'Broken pipe'/'Connection', re-init the terminal once and replay the command."],"exampleFix":"# before\nout = await term.execute(cmd)\n\n# after\ntry:\n    out = await term.execute(cmd)\nexcept RuntimeError as e:\n    if \"Broken pipe\" in str(e) or \"Connection\" in str(e):\n        await term.close()\n        await term.init()          # fresh exec session on same container\n        out = await term.execute(cmd)\n    else:\n        raise","handlingStrategy":"retry","validationCode":"container.reload()\nif container.status != 'running':\n    raise RuntimeError(f'container {container.short_id} is {container.status}')","typeGuard":null,"tryCatchPattern":"try:\n    out = await term.execute(cmd)\nexcept RuntimeError as e:\n    msg = str(e)\n    if 'Broken pipe' in msg or 'Connection reset' in msg or 'closed' in msg.lower():\n        await term.close()\n        await term.init()\n        out = await term.execute(cmd)\n    else:\n        raise","preventionTips":["Check container status before long command sequences.","Serialize session access with an asyncio.Lock.","Log the embedded '{e}' cause — it identifies daemon restarts vs parsing bugs."],"tags":["docker","broken-pipe","terminal","session-recovery"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}