From 0e7202caeee689ad9bbfa5c4182a2f30e471ae7d Mon Sep 17 00:00:00 2001 From: D41910 <158550716+D41910@users.noreply.github.com> Date: Fri, 9 Oct 2026 03:55:25 +0800 Subject: [PATCH] Honor an empty allow list in the bash agent tool (#1362) --- src/python/txtai/agent/tool/bash.py | 2 +- test/python/testagent.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/python/txtai/agent/tool/bash.py b/src/python/txtai/agent/tool/bash.py index c000a19c..b847c5e5 100644 --- a/src/python/txtai/agent/tool/bash.py +++ b/src/python/txtai/agent/tool/bash.py @@ -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 diff --git a/test/python/testagent.py b/test/python/testagent.py index 107ca317..e5b1a024 100644 --- a/test/python/testagent.py +++ b/test/python/testagent.py @@ -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): """