Autonomous-AI / tools /code_runner.py
Leonydis137's picture
Create code_runner.py
02c72c4 verified
raw
history blame contribute delete
308 Bytes
import subprocess
def run_python_code(code: str):
try:
with open("temp.py", "w") as f:
f.write(code)
result = subprocess.check_output(["python3", "temp.py"], stderr=subprocess.STDOUT, timeout=5)
return result.decode()
except Exception as e:
return str(e)