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
IPython does not respect sys.flags.safe_path (aka, PYTHONSAFEPATH or -P) #15013
IPython currently ignores Python's PYTHONSAFEPATH environment variable and -P command line flag, which were introduced in Python 3.11 to prevent potentially unsafe paths from being added to sys.path. I am suggesting IPython should respect that flag.
Current Behavior
When running PYTHONSAFEPATH=1 ipython or python -P -m IPython, IPython still adds an empty string ('') to sys.path, causing it to search the current working directory for modules.
This can lead to unintended imports of local files over installed packages. It can also introduce security concerns as described in ohmyzsh/ohmyzsh#12535
IPython has its own flag (--ignore-cwd) to avoid this issue at the moment.
Therefore, right now, the easiest way to configure ipython to respect sys.flags.safe_path, is likely to configure ipython_config.py so that one flag is driven by the other, with lines like:
In addition to its own flag, IPython should also respect sys.flags.safe_pathand not add the current working directory to sys.path when the safe path mode is enabled, similar to how the existing --ignore-cwd flag works.
Proposed Solution
Modify the init_path() method in /IPython/core/shellapp.py line 259 to also check sys.flags.safe_path.
@algal thanks for opening the issue and pointing to an implementation. Looks pretty straightforward, so please do open a PR when you get a chance, you'll also want to add a note about the chang in the docs/source/whatsnew/pr folder, so it makes it into the release notes, see https://github.com/ipython/ipython/blob/main/docs/source/whatsnew/pr/README.md for details.
The only thing here which is not ready to merge is that I did not know how I should set the version number within the updated docstring. I'm not familiar with the IPython release schedule and policy, so I'm not sure what version this will finally land in.
Activity
ivanov commentedon Oct 6, 2025
@algal thanks for opening the issue and pointing to an implementation. Looks pretty straightforward, so please do open a PR when you get a chance, you'll also want to add a note about the chang in the docs/source/whatsnew/pr folder, so it makes it into the release notes, see https://github.com/ipython/ipython/blob/main/docs/source/whatsnew/pr/README.md for details.
algal commentedon Oct 6, 2025
@ivanov I created a PR which implements this change. It includes the PR what's new note, as described in that README.md.
#15014
The only thing here which is not ready to merge is that I did not know how I should set the version number within the updated docstring. I'm not familiar with the IPython release schedule and policy, so I'm not sure what version this will finally land in.
krassowski commentedon Oct 7, 2025
I suppose we can close this issue since #15014 was merged