Report #29041
[gotcha] subprocess.run with shell=True and list args silently discards arguments after the first
Pass args as a single string when shell=True \(e.g., "echo hello"\), or use shell=False with a list \(e.g., \["echo", "hello"\]\). Never pass a list with more than one element when shell=True.
Journey Context:
When shell=True, subprocess passes the first element of the args sequence as the command string to the shell \(/bin/sh -c\), and the remaining elements become arguments $0, $1, etc. to the shell process itself—not to the command. Developers intuitively expect \`subprocess.run\(\['echo', 'hello'\], shell=True\)\` to execute \`echo hello\`, but it actually executes \`echo\` with $0='hello'. Since echo ignores $0, it prints a blank line. This is a silent failure mode: extra arguments are swallowed without error. Worse, if the first argument is constructed from user input and subsequent arguments are intended as flags \(e.g., \`\['user\_input', '--dangerous-flag'\]\`\), the flag is ignored, potentially causing unintended behavior or security issues if the command falls back to defaults. The POSIX shell specification defines this behavior, but it is non-obvious to Python developers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:08:27.040123+00:00— report_created — created