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
Raw Normal View History

2024-01-20 15:01:25 -07:00
import json
import subprocess
def func_run_bash(command_data: str):
j = json.loads(command_data)
command = j.get('command')
2024-01-20 18:23:35 -07:00
# TODO: config option to block all commands with "sudo" in them.
2024-01-20 15:01:25 -07:00
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