Execute a bash sample.
(code: str)
| 95 | |
| 96 | |
| 97 | def run_bash_sample(code: str) -> Dict[str, Any]: |
| 98 | """Execute a bash sample.""" |
| 99 | try: |
| 100 | result = subprocess.run( |
| 101 | code, |
| 102 | shell=True, |
| 103 | capture_output=True, |
| 104 | text=True, |
| 105 | timeout=10, |
| 106 | ) |
| 107 | return { |
| 108 | 'passed': result.returncode == 0, |
| 109 | 'returncode': result.returncode, |
| 110 | 'stdout': result.stdout[:200], |
| 111 | 'stderr': result.stderr[:200], |
| 112 | } |
| 113 | except subprocess.TimeoutExpired: |
| 114 | return { |
| 115 | 'passed': False, |
| 116 | 'error': 'Timeout (10s)', |
| 117 | } |
| 118 | except Exception as e: |
| 119 | return { |
| 120 | 'passed': False, |
| 121 | 'error': str(e), |
| 122 | } |
| 123 | |
| 124 | |
| 125 | def run_python_sample(code: str) -> Dict[str, Any]: |