You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid shell=True in nnUNetV2Runner.train_parallel while preserving per-device command order #8992
nnUNetV2Runner.train_parallel currently joins each device's argument-list commands with ; and starts the resulting string with subprocess.Popen(..., shell=True).
The commands appear to be constructed internally, so I am not reporting this as a confirmed command-injection vulnerability. However, invoking a shell is unnecessary here and increases the attack surface if command construction changes in the future.
Describe the solution you'd like
Run each device's commands sequentially with shell=False, while retaining parallel execution across devices. One possible implementation is:
one worker per active device;
commands within a device are executed in their original order;
different devices run concurrently;
each command keeps its associated environment;
empty stages are skipped.
I prepared and locally checked a proof-of-concept patch. The checks cover command order, list arguments, shell=False, empty-stage handling, Python compilation, and patch applicability. I have not run MONAI's complete nnUNet integration test suite, so I would appreciate maintainer guidance on the preferred test location and whether this change fits the current design.
Alternatives considered
Splitting the semicolon-joined string with shlex.split was rejected because it changes command semantics. Launching every command at once was also rejected because commands assigned to the same GPU must remain sequential.
Additional context
This suggestion came from a static-analysis validation exercise against MONAI. The initial rule finding was manually reviewed before filing this request, and this issue is intentionally framed as defense-in-depth rather than a confirmed vulnerability.
+1 on moving train_parallel off shell=True — the per-device commands are constructed internally today, so this is defense-in-depth rather than a live injection, but dropping the shell is a clean hardening.
One extra thing worth accounting for in the rewrite: the current code doesn't just lose the shell surface, it also already drops per-command env. At nnunetv2_runner.py:743-746 the whole "; "-joined chain for a device runs under only the first command's env:
cmd_str="; ".join(shlex.join(cmd) forcmd, _instage[device_id])
env=stage[device_id][0][1] # only the first command's env is usedprocesses.append(subprocess.Popen(cmd_str, shell=True, env=env, ...))
So if two commands on the same device ever carry different envs, the later ones silently run under the wrong one. A one-worker-per-device approach that runs each (cmd, env) sequentially with shell=False fixes both issues at once — each command keeps its own env, order within a device is preserved, and devices still run concurrently. Just flagging so it's covered in whichever implementation lands. Thanks for filing this!
Activity
MDSALMANSHAMS commentedon Jul 14, 2026
+1 on moving
train_paralleloffshell=True— the per-device commands are constructed internally today, so this is defense-in-depth rather than a live injection, but dropping the shell is a clean hardening.One extra thing worth accounting for in the rewrite: the current code doesn't just lose the shell surface, it also already drops per-command env. At
nnunetv2_runner.py:743-746the whole"; "-joined chain for a device runs under only the first command's env:So if two commands on the same device ever carry different envs, the later ones silently run under the wrong one. A one-worker-per-device approach that runs each
(cmd, env)sequentially withshell=Falsefixes both issues at once — each command keeps its own env, order within a device is preserved, and devices still run concurrently. Just flagging so it's covered in whichever implementation lands. Thanks for filing this!