diff --git a/aider/args.py b/aider/args.py index 928a73281..91137539a 100644 --- a/aider/args.py +++ b/aider/args.py @@ -965,6 +965,11 @@ def get_parser(default_config_files, git_root): " specified, a default command for your OS may be used." ), ) + group.add_argument( + "--command-prefix", + default=None, + help="Specify a command prefix for all commands (useful for sandboxing)", + ) group.add_argument( "--detect-urls", action=argparse.BooleanOptionalAction, diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index fd8320bdc..8ab6030b9 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -3837,6 +3837,10 @@ class Coder: if not command or command.startswith("#"): continue + if command and getattr(self.args, "command_prefix", None): + command_prefix = getattr(self.args, "command_prefix", None) + command = f"{command_prefix} {command}" + self.io.tool_output() self.io.tool_output(f"Running {command}") # Add the command to input history diff --git a/aider/tools/command.py b/aider/tools/command.py index 7c539c7f9..cfed959bc 100644 --- a/aider/tools/command.py +++ b/aider/tools/command.py @@ -32,6 +32,9 @@ class Tool(BaseTool): # Ask for confirmation before executing. # allow_never=True enables the 'Always' option. # confirm_ask handles remembering the 'Always' choice based on the subject. + if command_string and getattr(coder.args, "command_prefix", None): + command_prefix = getattr(coder.args, "command_prefix", None) + command_string = f"{command_prefix} {command_string}" confirmed = ( True diff --git a/aider/tools/command_interactive.py b/aider/tools/command_interactive.py index 5d25a36f1..1ccb621f7 100644 --- a/aider/tools/command_interactive.py +++ b/aider/tools/command_interactive.py @@ -31,6 +31,10 @@ class Tool(BaseTool): Execute an interactive shell command using run_cmd (which uses pexpect/PTY). """ try: + if command_string and getattr(coder.args, "command_prefix", None): + command_prefix = getattr(coder.args, "command_prefix", None) + command_string = f"{command_prefix} {command_string}" + confirmed = ( True if coder.skip_cli_confirmations