AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Don't incapacitate yourself! (#1240)
lfrickend4860fe9f09d
diff --git a/autogpt/app.py b/autogpt/app.pyindex 19c075f0b0..6f51fd98fb 100644--- a/autogpt/app.py+++ b/autogpt/app.py@@ -10,7 +10,11 @@ from autogpt.config import Configfrom autogpt.commands.image_gen import generate_imagefrom autogpt.commands.audio_text import read_audio_from_filefrom autogpt.commands.web_requests import scrape_links, scrape_text-from autogpt.commands.execute_code import execute_python_file, execute_shell+from autogpt.commands.execute_code import (+ execute_python_file,+ execute_shell,+ execute_shell_popen,+)from autogpt.commands.file_operations import (append_to_file,delete_file,@@ -191,6 +195,15 @@ def execute_command(command_name: str, arguments):" shell commands, EXECUTE_LOCAL_COMMANDS must be set to 'True' ""in your config. Do not attempt to bypass the restriction.")+ elif command_name == "execute_shell_popen":+ if CFG.execute_local_commands:+ return execute_shell_popen(arguments["command_line"])+ else:+ return (+ "You are not allowed to run local shell commands. To execute"+ " shell commands, EXECUTE_LOCAL_COMMANDS must be set to 'True' "+ "in your config. Do not attempt to bypass the restriction."+ )elif command_name == "read_audio_from_file":return read_audio_from_file(arguments["file"])elif command_name == "generate_image":diff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.pyindex 2cc797cbba..e2a8d994aa 100644--- a/autogpt/commands/execute_code.py+++ b/autogpt/commands/execute_code.py@@ -114,6 +114,36 @@ def execute_shell(command_line: str) -> str:return output+def execute_shell_popen(command_line):+ """Execute a shell command with Popen and returns an english description+ of the event and the process id++ Args:+ command_line (str): The command line to execute++ Returns:+ str: Description of the fact that the process started and its id+ """+ current_dir = os.getcwd()++ if WORKING_DIRECTORY not in current_dir: # Change dir into workspace if necessary+ work_dir = os.path.join(os.getcwd(), WORKING_DIRECTORY)+ os.chdir(work_dir)++ print(f"Executing command '{command_line}' in working directory '{os.getcwd()}'")++ do_not_show_output = subprocess.DEVNULL+ process = subprocess.Popen(+ command_line, shell=True, stdout=do_not_show_output, stderr=do_not_show_output+ )++ # Change back to whatever the prior working dir was++ os.chdir(current_dir)++ return f"Subprocess started with PID:'{str(process.pid)}'"++def we_are_running_in_a_docker_container() -> bool:"""Check if we are running in a Docker containerdiff --git a/autogpt/prompt.py b/autogpt/prompt.pyindex a2b20b1fef..33098af035 100644--- a/autogpt/prompt.py+++ b/autogpt/prompt.py@@ -38,6 +38,9 @@ def get_prompt() -> str:prompt_generator.add_constraint('Exclusively use the commands listed in double quotes e.g. "command name"')+ prompt_generator.add_constraint(+ "Use subprocesses for commands that will not terminate within a few minutes"+ )# Define the command listcommands = [@@ -81,6 +84,7 @@ def get_prompt() -> str:{"code": "<full_code_string>", "focus": "<list_of_focus_areas>"},),("Execute Python File", "execute_python_file", {"file": "<file>"}),+ ("Task Complete (Shutdown)", "task_complete", {"reason": "<reason>"}),("Generate Image", "generate_image", {"prompt": "<prompt>"}),("Send Tweet", "send_tweet", {"text": "<text>"}),]@@ -104,6 +108,13 @@ def get_prompt() -> str:{"command_line": "<command_line>"},),)+ commands.append(+ (+ "Execute Shell Command Popen, non-interactive commands only",+ "execute_shell_popen",+ {"command_line": "<command_line>"}+ ),+ )# Only add the download file command if the AI is allowed to execute itif cfg.allow_downloads: