Executing code provided by untrusted user using exec eval or ast.literal eval
suggest changeIt is not possible to use eval or exec to execute code from an untrusted user securely. Even ast.literal_eval can fail on hostile input. It is sometimes possible to guard against malicious code execution, but that does not make eval or exec safe, and it does not rule out parser or tokenizer failures.
To evaluate code from an untrusted user you need to turn to some third-party module, or perhaps write your own parser and your own virtual machine in Python.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents