Spot the bug in the tool executor

from AI coding agents
Python 3.14 intermediate 6 min 3 issues to find

Find the security failures in this generated tool executor.

Python
from pathlib import Path
import subprocess

WORKSPACE = Path("/srv/project")

def read_file(raw_path: str) -> str:
    resolved = Path(raw_path).resolve()
    if not str(resolved).startswith(str(WORKSPACE.resolve())):
        raise PermissionError(raw_path)
    return resolved.read_text()

def run(command: str) -> str:
    result = subprocess.run(
        command, shell=True, capture_output=True, text=True
    )
    return result.stdout
Open in playground
Report an error