File size: 1,088 Bytes
fbf3c28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
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}