adaptai / projects /oui-max /tools /run_bash_command.py
ADAPT-Chase's picture
Add files using upload-large-folder tool
fbf3c28 verified
"""
id: run_bash_command
title: Run Bash Command (unsafe)
author: admin
description: Run a bash command on the host without sandbox. For trusted admin use only.
version: 0.1.0
license: Proprietary
"""
import subprocess
class Tools:
def __init__(self):
pass
def bash(self, command: str) -> dict:
"""
Run a shell command and return stdout, stderr, and exit_code.
:param command: The shell command to run (e.g., 'date').
:return: {"stdout": str, "stderr": str, "exit_code": int}
"""
try:
p = subprocess.run(
["bash", "-lc", command], capture_output=True, text=True, timeout=60
)
return {"stdout": p.stdout, "stderr": p.stderr, "exit_code": p.returncode}
except subprocess.TimeoutExpired as e:
return {
"stdout": e.stdout or "",
"stderr": (e.stderr or "") + "\n[timeout]",
"exit_code": 124,
}
except Exception as e:
return {"stdout": "", "stderr": str(e), "exit_code": 1}