AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

Allow for other executable file types to be ran within command "execute_code.py"

Open shiralitech opened this issue 1 year ago • 4 comments

Summary 💡

Add the ability for other executable files to be run with command "execute_code.py" (Currently only .py files are implemented)

shiralitech avatar Apr 22 '23 01:04 shiralitech

use the execute_code to run SHELL, I can run pretty much run all terminal commands, once shell is being used.

enixlabs avatar Apr 22 '23 08:04 enixlabs

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?

shiralitech avatar Apr 22 '23 18:04 shiralitech

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"

kavikon avatar Apr 23 '23 08:04 kavikon

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.

Boostrix avatar May 08 '23 13:05 Boostrix

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.

github-actions[bot] avatar Sep 06 '23 21:09 github-actions[bot]

This issue was closed automatically because it has been stale for 10 days with no activity.

github-actions[bot] avatar Sep 17 '23 01:09 github-actions[bot]