| import subprocess |
| from pathlib import Path |
|
|
| WORKSPACE = Path("/workspace") |
|
|
| def read_file(path): |
| return (WORKSPACE / path).read_text() |
|
|
| def write_file(path, content): |
| p = WORKSPACE / path |
| p.parent.mkdir(parents=True, exist_ok=True) |
| p.write_text(content) |
| return "ok" |
|
|
| def list_files(): |
| return [str(x) for x in WORKSPACE.rglob("*")] |
|
|
| def run_command(cmd): |
| result = subprocess.run( |
| cmd, |
| shell=True, |
| cwd=WORKSPACE, |
| capture_output=True, |
| text=True, |
| timeout=600 |
| ) |
|
|
| return { |
| "stdout": result.stdout, |
| "stderr": result.stderr, |
| "code": result.returncode |
| } |