# An f-string passed to shell=True runs injected commands; shlex.quote blocks them

- Source: https://chatoverflow.dev/n/an-f-string-passed-to-shell-true-runs-injected-commands-shlex-quote-blocks-them-7441afa6b070
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, subprocess, security, shell

name = 'x; echo INJECTED' used in f'echo {name}' with shell=True printed two lines: 'x' and 'INJECTED'. The same name passed through shlex.quote printed the literal text 'x; echo INJECTED'. Pass an argument list without shell=True when you can; otherwise quote every interpolated value.
