AutoGPT
AutoGPT copied to clipboard
Allow for other executable file types to be ran within command "execute_code.py"
Summary 💡
Add the ability for other executable files to be run with command "execute_code.py" (Currently only .py files are implemented)
use the execute_code to run SHELL, I can run pretty much run all terminal commands, once shell is being used.
for 1 of the 5 goals do I explicitly state this?
(ps:do you also know how to fix the error 127 relating to chromium drivers in the "web_selenium" command when dealing in WSL distro?
Use the below code to add to execute_code.py
def execute_file(file: str) -> str: """Execute a file in a Docker container and return the output
Args:
file (str): The name of the file to execute
Returns:
str: The output of the file
"""
print(f"Executing file '{file}' in workspace '{WORKSPACE_PATH}'")
file_ext = os.path.splitext(file)[1]
if file_ext not in [".py", ".sh", ".rb", ".js"]:
return f"Error: Invalid file type. Supported file types are .py, .sh, .rb, and .js."
file_path = path_in_workspace(file)
if not os.path.isfile(file_path):
return f"Error: File '{file}' does not exist."
if we_are_running_in_a_docker_container():
result = subprocess.run(
f"{file_path}", capture_output=True, encoding="utf8", shell=True
)
if result.returncode == 0:
return result.stdout
else:
return f"Error: {result.stderr}"
# Set default image name based on file extension
image_name = None
if file_ext == ".py":
image_name = "python:3-alpine"
elif file_ext == ".sh":
image_name = "bash"
elif file_ext == ".rb":
image_name = "ruby"
elif file_ext == ".js":
image_name = "node"
definitely useful AND dangerous, probably should be strictly opt-in via a corresponding env option, and should only be made available automatically when inside a docker container. Other than that, that would be a powerful thing obviously.
This issue has automatically been marked as stale because it has not had any activity in the last 50 days. You can unstale it by commenting or removing the label. Otherwise, this issue will be closed in 10 days.
This issue was closed automatically because it has been stale for 10 days with no activity.