Skip to content

fix(tools): execute bash commands as argv with shell=False - #1930

Open
tripathiji1312 wants to merge 1 commit into
kyegomez:masterfrom
tripathiji1312:fix/bash-tool-hardening
Open

fix(tools): execute bash commands as argv with shell=False#1930
tripathiji1312 wants to merge 1 commit into
kyegomez:masterfrom
tripathiji1312:fix/bash-tool-hardening

Conversation

@tripathiji1312

Copy link
Copy Markdown

Summary

run_bash_tool previously ran subprocess.run(command, shell=True), handing the command string to /bin/sh. Shell metacharacters were live, so a prompt like echo hi > /dev/sda or |sh could execute arbitrary commands — the tool was effectively a remote shell for any agent with tool access.

Changes

  • Commands are parsed with shlex.split and executed as argv with shell=False: metacharacters become inert literal tokens (a redirection attempt fails to exec instead of writing to disk).
  • The dangerous-command blocklist is checked both on the raw string and on the parsed token list, closing two bypasses of the old substring check:
    • r""m -rf / (quoted-concat hides the rm substring)
    • rm -r -f / (split flags evade the rm -rf substring)
  • New blocklist entries: rm -r -f, rm --recursive --force, rm -rf /, chmod 777.
  • Rejected commands are logged and recorded in agent short memory as Blocked (security): ...; unparseable input (unbalanced quotes, NUL bytes) is rejected without execution.

Tests

  • New tests/structs/test_autonomous_loop_utils.py (20 tests): raw-string and argv-level blocklist coverage, quoted-concat and split-flag bypasses, NUL/empty argv rejection, shell-metacharacter inertness (>/dev/sda, |sh fail to exec), benign command execution, and short-memory recording of blocked commands.

run_bash_tool previously ran subprocess.run(command, shell=True),
which handed the command string to /bin/sh: shell metacharacters were
live, so a prompt like 'echo hi > /dev/sda' or '|sh' could execute
arbitrary commands. The command is now parsed with shlex.split and
executed as argv with shell=False, making metacharacters inert.

The dangerous-command blocklist is checked both on the raw string and
on the parsed token list, closing the r""m -rf / (quoted-concat) and
rm -r -f / (split-flag) bypasses of the old substring check. New
entries: rm -r -f, rm --recursive --force, rm -rf /, chmod 777.
Rejected commands are logged and recorded in agent short memory.
@github-actions

Copy link
Copy Markdown

Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant