Spaces:
Sleeping
Sleeping
Download tools/bash_executor.py from KrilinZ/neuronalis: direct link, hf CLI and curl.
- Browser
- Download file 824 Bytes
-
https://huggingface.co/spaces/KrilinZ/neuronalis/resolve/main/tools/bash_executor.py
- Command line
-
hf download hf://spaces/KrilinZ/neuronalis/tools/bash_executor.py
-
curl -L -o bash_executor.py https://huggingface.co/spaces/KrilinZ/neuronalis/resolve/main/tools/bash_executor.py
824 Bytes
| 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}" | |