Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(tools): execute Windows shell commands through cmd instead of echoing them

Ruben Lütkea216663cb360
diff --git a/docs/BUGS.md b/docs/BUGS.md
index a4c5c68229..116fe804af 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -3626,3 +3626,38 @@ fallback, deferred readback reaches the idle live model at the boundary.
**Class rule.** A voice surface has ONE voice at a time. Any fallback from
the live realtime voice to classic TTS must be gated on the live call being
GONE, never merely busy — "busy" means wait or drop, not switch voices.
+
+## BUG-050: run_shell on Windows echoes quoted commands instead of executing them (HIGH, 2026-07-13)
+
+**Symptom.** In a realtime session (18:15) the delegated brain turn burned all
+15 tool iterations trying to list the user's wiki files and died with
+`IterationBudget exhausted` — spoken outcome: a generic failure. The user
+experienced it as an endless thinking loop.
+
+**Root cause.** `run_shell` tokenized with `shlex.split(posix=False)` on
+Windows, which KEEPS surrounding quotes inside tokens. Three failure shapes,
+two of them silent:
+
+1. `powershell -Command "Get-ChildItem -Name"` → PowerShell received a string
+ LITERAL and echoed it back — **exit 0, stdout = the command itself**. The
+ tool reported success with garbage output, so the model saw no error to
+ correct and retried variations until the budget died.
+2. `cmd.exe /c "dir /s /b *.md"` → the kept quotes corrupted the payload
+ ("Der Befehl ist entweder falsch geschrieben..."). <!-- i18n-allow: quoted German OS error under test -->
+3. `dir /s /b` → WinError 2: cmd builtins are not programs and cannot be
+ exec'd directly.
+
+**Fix.** On Windows the ORIGINAL command string goes to `cmd.exe` via
+`create_subprocess_shell` — cmd parses its own quoting and provides the
+builtins. POSIX keeps the historical `shlex.split` + exec contract. The
+whitelist/blacklist safety matching runs on the full command string in
+`ToolExecutor` BEFORE execution and is unchanged.
+
+**Guards.** `tests/unit/plugins/tool/test_run_shell.py` — quoted PowerShell
+payload is executed (not echoed), cmd builtin `dir` works, quoted cmd payload
+works, POSIX path pinned.
+
+**Class rule.** A tool that reports success with an output that is merely its
+own input is worse than a failing tool: the model gets no error signal and
+loops. When wrapping OS process creation, verify on EVERY platform that a
+quoted argument arrives as an argument, not as a literal.
diff --git a/jarvis/plugins/tool/run_shell.py b/jarvis/plugins/tool/run_shell.py
index c922864099..ddd38a8a94 100644
--- a/jarvis/plugins/tool/run_shell.py
+++ b/jarvis/plugins/tool/run_shell.py
@@ -1,10 +1,21 @@
"""run_shell tool: runs shell commands (via subprocess).
-Risk tier: monitor — the safety layer decides via whitelist/blacklist whether confirmation is needed.
+Risk tier: monitor — the safety layer decides via whitelist/blacklist whether
+confirmation is needed. The whitelist/blacklist matching runs on the FULL
+command string inside ``ToolExecutor`` before this tool executes, so it is
+independent of how the string is executed below.
-The tool does NOT invoke `shell=True` mode. Commands are parsed through
-`shlex.split`. The user can move dangerous commands into the safe tier
-via `[safety.whitelist].commands` (`browser-use *`, `git *`).
+POSIX keeps the historical no-``shell=True`` contract: commands are parsed
+through ``shlex.split`` and exec'd directly.
+
+Windows hands the ORIGINAL string to ``cmd.exe`` instead. Tokenizing with
+``shlex.split(posix=False)`` KEPT the surrounding quotes inside the tokens,
+so ``powershell -Command "X"`` received a string LITERAL and echoed it back
+with exit 0 — the tool reported success with garbage output, which sent the
+delegated brain into a retry loop until its iteration budget died (forensic
+2026-07-13 18:15). cmd builtins (``dir``, ``type``, ``copy``) additionally
+failed with WinError 2 because they are not programs. ``cmd.exe`` parses its
+own quoting and provides the builtins.
"""
from __future__ import annotations
@@ -41,19 +52,31 @@ class RunShellTool:
if not command:
return ToolResult(success=False, output=None, error="command is missing")
- try:
- parts = shlex.split(command, posix=(sys.platform != "win32"))
- except ValueError as exc:
- return ToolResult(success=False, output=None, error=f"Command parse error: {exc}")
+ if sys.platform != "win32":
+ try:
+ parts = shlex.split(command)
+ except ValueError as exc:
+ return ToolResult(
+ success=False, output=None, error=f"Command parse error: {exc}"
+ )
try:
- proc = await asyncio.create_subprocess_exec(
- *parts,
- stdout=asyncio.subprocess.PIPE,
- stderr=asyncio.subprocess.PIPE,
- cwd=cwd,
- creationflags=NO_WINDOW_CREATIONFLAGS,
- )
+ if sys.platform == "win32":
+ proc = await asyncio.create_subprocess_shell(
+ command,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ cwd=cwd,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ )
+ else:
+ proc = await asyncio.create_subprocess_exec(
+ *parts,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ cwd=cwd,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ )
try:
stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout=timeout_s)
except TimeoutError:
diff --git a/tests/unit/plugins/tool/test_run_shell.py b/tests/unit/plugins/tool/test_run_shell.py
new file mode 100644
index 0000000000..cf6772b742
--- /dev/null
+++ b/tests/unit/plugins/tool/test_run_shell.py
@@ -0,0 +1,72 @@
+"""run_shell must EXECUTE commands, not echo them back as text.
+
+Forensic 2026-07-13 18:15: on Windows, ``shlex.split(posix=False)`` kept the
+surrounding quotes inside tokens, so ``powershell -Command "X"`` received a
+string literal and echoed it with exit 0 — a false success that sent the
+delegated brain into a retry loop until its iteration budget was exhausted.
+"""
+
+from __future__ import annotations
+
+import sys
+
+import pytest
+
+from jarvis.plugins.tool.run_shell import RunShellTool
+
+windows_only = pytest.mark.skipif(
+ sys.platform != "win32", reason="Windows shell semantics"
+)
+posix_only = pytest.mark.skipif(
+ sys.platform == "win32", reason="POSIX exec semantics"
+)
+
+
+async def test_empty_command_is_rejected() -> None:
+ result = await RunShellTool().execute({"command": " "}, None)
+ assert result.success is False
+
+
+@windows_only
+async def test_quoted_powershell_command_is_executed_not_echoed() -> None:
+ result = await RunShellTool().execute(
+ {"command": 'powershell -Command "Write-Output hello-from-ps"'},
+ None,
+ )
+ assert result.success is True
+ stdout = result.output["stdout"]
+ assert "hello-from-ps" in stdout
+ assert "Write-Output" not in stdout
+
+
+@windows_only
+async def test_cmd_builtin_dir_works(tmp_path) -> None:
+ (tmp_path / "probe-file.md").write_text("x", encoding="utf-8")
+ result = await RunShellTool().execute(
+ {"command": "dir /b", "cwd": str(tmp_path)},
+ None,
+ )
+ assert result.success is True
+ assert "probe-file.md" in result.output["stdout"]
+
+
+@windows_only
+async def test_quoted_cmd_payload_is_executed() -> None:
+ result = await RunShellTool().execute(
+ {"command": 'cmd.exe /c "echo quoted-ok"'},
+ None,
+ )
+ assert result.success is True
+ assert "quoted-ok" in result.output["stdout"]
+
+
+@posix_only
+async def test_posix_exec_path_unchanged() -> None:
+ result = await RunShellTool().execute({"command": "echo hello"}, None)
+ assert result.success is True
+ assert "hello" in result.output["stdout"]