Spaces:
Sleeping

File size: 824 Bytes
5a6158c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import subprocess
import shlex

def execute_command(command, timeout=30):
    """Executes a bash command."""
    try:
        # Basic security check
        forbidden = ['rm -rf /', ':(){ :|:& };:'] # Fork bomb
        for f in forbidden:
            if f in command:
                return "Error: Command blocked for security reasons."

        process = subprocess.run(
            command,
            shell=True,
            capture_output=True,
            text=True,
            timeout=timeout
        )
        
        output = process.stdout
        if process.stderr:
            output += f"\nSTDERR:\n{process.stderr}"
            
        return output
    except subprocess.TimeoutExpired:
        return "Error: Command timed out."
    except Exception as e:
        return f"Error executing command: {e}"