import subprocess def run_command(command: str, timeout: int = 30) -> str: try: result = subprocess.run( command, shell=True, capture_output=True, text=True, timeout=timeout ) output = "" if result.stdout: output += f"STDOUT:\n{result.stdout}" if result.stderr: output += f"\nSTDERR:\n{result.stderr}" output += f"\nExit code: {result.returncode}" return output if output.strip() else "Command ran successfully with no output." except subprocess.TimeoutExpired: return f"Error: Command timed out after {timeout} seconds." except Exception as e: return f"Error running command: {str(e)}"