Honor an empty allow list in the bash agent tool (#1362)

This commit is contained in:
D41910
2026-10-08 15:55:25 -04:00
committed by GitHub
parent c1f1686889
commit 0e7202caee
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ class BashTool(Tool):
self.output_type = "any"
# Default list of allowed commands
self.allowed = allowed if allowed else ["cat", "cut", "diff", "grep", "head", "ls", "tail"]
self.allowed = allowed if allowed is not None else ["cat", "cut", "diff", "grep", "head", "ls", "tail"]
# Maximum time to wait for a command, None waits indefinitely
self.timeout = timeout
+15
View File
@@ -232,6 +232,21 @@ class TestAgent(unittest.TestCase):
# Timeout is disabled when set to None
self.assertIsNone(BashTool(timeout=None).timeout)
def testToolsBashAllowedEmpty(self):
"""
Test an empty allowed commands list permits no commands
"""
# An empty allow list is an explicit choice and must be honored, not replaced by the defaults
self.assertEqual(BashTool(allowed=[]).allowed, [])
# No command runs when nothing is allowed
self.assertIsNone(BashTool(allowed=[])(["cat", "file.txt"]))
# The defaults still apply when allowed isn't set, including an explicit None
self.assertEqual(BashTool().allowed, ["cat", "cut", "diff", "grep", "head", "ls", "tail"])
self.assertEqual(BashTool(allowed=None).allowed, ["cat", "cut", "diff", "grep", "head", "ls", "tail"])
@patch("subprocess.run")
def testToolsBashEncoding(self, run):
"""