This repository has been archived on 2024-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
server-personification/lib/openai/bash.py

15 lines
456 B
Python

import json
import subprocess
def func_run_bash(command_data: str):
j = json.loads(command_data)
command = j.get('command')
# TODO: config option to block all commands with "sudo" in them.
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = process.communicate()
return_code = process.returncode
return stdout.decode('utf-8'), stderr.decode('utf-8'), return_code