I'm working on a mobile app that can execute Python code easily, and unlike other execution apps I am going to have it run with actual Python.
I'm using a Flask Webserver and requests to accomplish this.
This is my code:
@app.route('/exec')
def run():
exec(request.args.get("code"))
I want to override any print statements or output.
Using the string.replace
method and another function wont work because if someone uses code like print("Use the print() function to send output in Python!")
this would be problematic, and people may want to use the function name. I also want to output errors.
For anyone saying this is unsafe, I have properly sandboxed the server, it will reset around every hour and has a backup server.