FoundationAgents/OpenManus · error · RuntimeError
Failed to execute command: {e}
Error message
Failed to execute command: {e} What it means
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.
Source
Thrown at app/sandbox/core/terminal.py:216
continue
raise
output = b"\n".join(result_lines).decode("utf-8")
output = re.sub(r"\n\$ echo \$\$?.*$", "", output)
return output
if timeout:
result = await asyncio.wait_for(read_output(), timeout)
else:
result = await read_output()
return result.strip()
except asyncio.TimeoutError:
raise TimeoutError(f"Command execution timed out after {timeout} seconds")
except Exception as e:
raise RuntimeError(f"Failed to execute command: {e}")
def _sanitize_command(self, command: str) -> str:
"""Sanitizes the command string to prevent shell injection.
Args:
command: Raw command string.
Returns:
Sanitized command string.
Raises:
ValueError: If command contains potentially dangerous patterns.
"""
# Additional checks for specific risky commands
risky_commands = [
"rm -rf /",
"rm -rf /*",View on GitHub (pinned to 52a13f2a57)
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.
Example fix
# before
out = await term.execute(cmd)
# after
try:
out = await term.execute(cmd)
except RuntimeError as e:
if "Broken pipe" in str(e) or "Connection" in str(e):
await term.close()
await term.init() # fresh exec session on same container
out = await term.execute(cmd)
else:
raise Defensive patterns
Strategy: retry
Validate before calling
container.reload()
if container.status != 'running':
raise RuntimeError(f'container {container.short_id} is {container.status}') Try / catch
try:
out = await term.execute(cmd)
except RuntimeError as e:
msg = str(e)
if 'Broken pipe' in msg or 'Connection reset' in msg or 'closed' in msg.lower():
await term.close()
await term.init()
out = await term.execute(cmd)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to create sandbox: {e}
- Failed to get socket connection
- Session not initialized
- Command execution timed out after {timeout} seconds
- Terminal not initialized
AI-assisted analysis of FoundationAgents/OpenManus@52a13f2a57 (2026-08-15).
Data as JSON: /api/errors/ca2344cdba888fed.
Report an issue: GitHub.