Skip to content

security: remove shell=True from ReAct agent bash tool#169

Merged
Yif-Yang merged 1 commit into
microsoft:mainfrom
mchillakuru:security/react-agent-no-shell
Jul 26, 2026
Merged

security: remove shell=True from ReAct agent bash tool#169
Yif-Yang merged 1 commit into
microsoft:mainfrom
mchillakuru:security/react-agent-no-shell

Conversation

@mchillakuru

Copy link
Copy Markdown

What

Replace shell=True in the ReAct agent's bash tool with shlex.split + shell=False, and restrict the executable to a small allow-list (python, python3). The spreadsheet benchmark only needs Python to manipulate files, so this removes shell-metacharacter injection without losing functionality.

File: skillopt/envs/spreadsheetbench/react_agent.py

Security guarantee (and limits)

  • Does: eliminate shell interpretation of agent-supplied command strings; block non-Python executables.
  • Does not: restrict what the allowed Python process itself can do.

Tests

tests/test_react_agent_no_shell.py:

  • a disallowed command (e.g. curl ...) is blocked
  • an allowed python -c command runs
  • shell metacharacters (;) are passed as arguments, not interpreted, so a chained command does not execute

Context

One of several small PRs replacing bulk PR #166, per reviewer feedback to split and scope. Full suite green except 6 pre-existing Windows-only path-separator failures that also fail on main.

Parse the command with shlex.split and run with shell=False, and restrict the executable to a python/python3 allow-list. This removes shell metacharacter injection (the benchmark only needs Python to manipulate spreadsheets). Adds tests for the allow-list gate and non-interpretation of shell metacharacters.
Copilot AI review requested due to automatic review settings July 25, 2026 23:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the SpreadsheetBench ReAct agent’s bash tool by removing shell interpretation of agent-supplied command strings and restricting execution to Python, reducing shell-metacharacter injection risk while preserving required benchmark functionality.

Changes:

  • Replaces subprocess.run(..., shell=True) with shlex.split(...) + shell=False in _run_bash.
  • Adds an executable allow-list gate intended to restrict execution to python / python3.
  • Adds tests covering disallowed commands, allowed Python execution, and non-interpretation of shell metacharacters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
skillopt/envs/spreadsheetbench/react_agent.py Removes shell=True, tokenizes commands, and adds an executable allow-list before running subprocesses.
tests/test_react_agent_no_shell.py Adds regression tests asserting the hardening behavior (allow-list + metacharacter non-interpretation).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +263 to +266
exe_name = os.path.basename(parts[0]).lower()
# Strip .exe suffix on Windows (python.exe → python)
exe_stem = exe_name.split(".")[0]
if exe_stem not in _CMD_ALLOW:
@Yif-Yang
Yif-Yang merged commit b3d6b7d into microsoft:main Jul 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants