Open the context
Choose the project folder and name the files or behavior involved.
Run trusted Python text of at most 4096 characters in an existing directory with a 50–5000 ms timeout. Check Unicode output, failed exits and direct-child termination on timeout, rejecting invalid limits without claiming sandboxing or descendant cleanup.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import math, os, subprocess, sys
from pathlib import Path
def run_trusted_python(script, seconds, folder):
if type(script) is not str or len(script) > 4096:
raise ValueError("child.script")
if type(seconds) not in (int, float) or not .05 <= seconds <= 5 or not math.isfinite(seconds):
raise ValueError("child.timeout")
if not isinstance(folder, (str, Path)) or not Path(folder).is_dir():
raise ValueError("child.folder")
return subprocess.run([sys.executable, "-I", "-S", "-X", "utf8", "-c", script],
cwd=folder, timeout=seconds, capture_output=True, text=True,
encoding="utf-8", check=False,
creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.