diff --git a/gptme/tools/shell.py b/gptme/tools/shell.py index 96d260d7..b8fa3ae6 100644 --- a/gptme/tools/shell.py +++ b/gptme/tools/shell.py @@ -246,11 +246,20 @@ def execute_shell( assert not args cmd = code.strip() + whitelisted = False if cmd.startswith("$ "): cmd = cmd[len("$ ") :] + single_cmd = code.count("\n") + is_safe_cmd = False + if single_cmd < 1: + is_safe_cmd = any(code.startswith(safe_cmd) for safe_cmd in ['ls', 'stat', 'cd', 'cat']) + + if single_cmd < 1 and is_safe_cmd: + whitelisted = True + confirm = True - if ask: + if not whitelisted and ask: print_preview(f"$ {cmd}", "bash") confirm = ask_execute() print()