Safeguard
Security Guides•

Is Python 2 still safe to run? What the sunset means in practice

Python 2 was sunset on 1 January 2020 and the project will not fix new security problems. Learn how to find leftover Python 2 code and retire it safely.

Safeguard Security Team
3 min read

No. The Python project sunset Python 2 on 1 January 2020 and says it will not improve it after that date, even if someone finds a security problem. The last release, 2.7.18, came out in April 2020. Anything still running Python 2 has had no upstream security fixes for years.

What the sunset page says

The python.org sunset notice says the volunteers stopped working on Python 2 on 1 January 2020. No new bug reports, fixes or changes are made. The 2.7.18 release in April 2020 bundled only fixes made before the cutoff, and its timing was for the release managers' convenience.

The practical effect: every flaw found in the interpreter, its standard library or its bundled tools since then has no upstream fix. Some operating system vendors and commercial providers have offered their own patches for a time. Those are separate arrangements, and each has its own end date, so verify what applies to you.

Where Python 2 still hides

You are unlikely to start a new service on Python 2. The risk is in what nobody touches.

PlaceWhy it survives
Cron jobs and admin scriptsThey work, so nobody reopens them
Build and deploy toolingWritten once, copied between repos
Embedded in vendor productsShipped as an internal runtime
Old base imagesThe image tag never moved
Data science notebooksPinned to an old environment

A quick search helps: look for #!/usr/bin/env python2, print " statements without parentheses, python_requires in setup files and FROM python:2 in Dockerfiles.

Move off it

  1. List every script and service. For each, find an owner. If there is none, that is your first finding.
  2. Decide: migrate, replace or delete. Many old scripts can simply be deleted once someone asks who uses them.
  3. For code you keep, use a tool such as 2to3 or python-modernize to do the mechanical changes, then fix the rest by hand. Review diffs, because string and integer handling changed in Python 3.
  4. Add tests before the conversion, even rough ones that check outputs.
  5. Target a current supported version, not the oldest Python 3. See our post on the Python 3.10 end of life.
  6. Retire the Python 2 runtime from the host so it cannot come back.

If you cannot migrate yet

Isolate it. Run it in a container with no internet access, drop its privileges, and make sure it never parses untrusted data. Be especially careful with formats such as pickle, which is unsafe on untrusted input in every version. See what to do instead of pickle.

Quick check

Does running Python 2 in a container make it safe?

A container limits the blast radius. It does not fix flaws in the interpreter. Combine it with network limits and minimal privileges.

Is it enough to switch the shebang to python3?

No. The code has to be compatible. A shebang change on an unconverted script usually fails.

Where Safeguard fits

Safeguard's asset discovery and SBOM scanning help you find old runtimes across hosts and repositories. The free scan covers the code side.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.