agent-zero-core / sandbox_runner.py
Tsitsi19's picture
Update sandbox_runner.py
3761831 verified
raw
history blame contribute delete
556 Bytes
import subprocess
import tempfile
def sandbox_test(code):
try:
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".py") as tmp:
tmp.write(code)
tmp_path = tmp.name
result = subprocess.run(
["python3", tmp_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=3
)
if result.returncode != 0:
return False, result.stderr.decode("utf8")
return True, None
except Exception as e:
return False, str(e)