This tool is donation based and free. πŸ™ We're looking for donations to keep it running β€” $360/year covers our server costs.

$18 of $360 Β· 5%
Donate
This fact check is over 4 months old. The situation may have changed significantly β€” please recheck before relying on it.

Can Input Execute English Code Safely

β€œDoes input = input('English goes here: ') exec(input) work”
Yes, but unsafe
Confidence: High Checked on April 14, 2026

Summary

The statement reads a line from the user and passes that string to `exec()`, which will execute it if it contains valid Python code, so it functions as written. However, executing raw user input is insecure and can cause syntax errors or security vulnerabilities.

Recheck this fact Runs a fresh check with up-to-date sources

Sources 58 searched

cs.stanford.edu
  • input()

    Regular Python programs typically do not use input() to get their data, instead using command line arguments.

geeksforgeeks.org
  • Input and Output in Python - GeeksforGeeks

    The print() function allows us to display text, variables and expressions on the console. In the below example, "Hello, World!" is a string literal enclosed within double quotes. When executed, this statement will output the text to the console.

  • Python input() Function - GeeksforGeeks

    Since we used int(), both inputs are integers, and addition works correctly. ... Sometimes, you may want to take a list from the user. Since input() returns a string, we can use list() or .split() to convert it into a list. ... a = list(input("List1: ")) b = list(input("List2: ")) for i in b: a.append(i) print("Final List:", a) ... Here, "abc" becomes ['a', 'b', 'c'], "xy" becomes ['x', 'y'] then b is appended into a.

  • exec() in Python - GeeksforGeeks

    If it is a string, the string is parsed as a suite of Python statements which is then executed unless a syntax error occurs and if it is an object code, it is simply executed. We must be careful that the return statements may not be used outside ...

pythongeeks.org
  • Python exec() with Examples - Python Geeks

    We can also give multiline inputs using triple quoted strings. For example, ... We can give loops, conditionals, and user-defined functions. For example, Example of exec() with for loop and conditional as input string:

docs.python.org
  • Built-in Functions β€” Python 3.14.4 documentation

    In all cases, the code that’s executed is expected to be valid as file input (see the section File input in the Reference Manual). Be aware that the nonlocal, yield, and return statements may not be used outside of function definitions even within the context of code passed to the exec() function.

owasp.org
  • Command Injection | OWASP Foundation

    Runtime.exec does NOT try to invoke the shell at any point. The key difference is that much of the functionality provided by the shell that could be used for mischief (chaining commands using β€œ&”, β€œ&&”, β€œ|”, β€œ||”, etc, redirecting input and output) would simply end up as a parameter being passed to the first command, and likely causing a syntax error, or being thrown out as an invalid parameter.

  • M4: Insufficient Input/Output Validation | OWASP Foundation

    Insufficient Input Validation: When user input is not thoroughly checked, attackers can manipulate it by entering unexpected or malicious data. This can bypass security measures and lead to code execution vulnerabilities or unauthorized system ...

stackoverflow.com

This fact check is free and donation-based. $1 powers ~30 fact-checks.

Donate $1 to support fact-checking

Check another fact