packaged by Chainguard
docker pull cgr.dev/chainguard/python
Need access to a specific tag? Contact us.
Pull CVE-free container images and gain access to malware-resistant Python, Java, and JavaScript libraries rebuilt from verified source.
Sign upMinimal Python image based on Wolfi.
Chainguard Containers are regularly-updated, secure-by-default container images.
For those with access, this container image is available on cgr.dev:
Be sure to replace the ORGANIZATION placeholder with the name used for your organization's private repository within the Chainguard Registry.
The python Chainguard Image provides a minimal Python runtime suitable for workloads such as web applications, CLI utilities, interfacing with APIs, or other tasks.
We have three image variants available:
python:latest-dev variant that contains the pip, uv, and apk package managers and the bash, ash, and sh shells.-full variant, which acts as an upstream-compatible drop-in replacement for the corresponding upstream image.
To pull the minimal runtime variant from cgr.dev:
To pull the dev variant:
The entrypoint for the python Chainguard Image is /usr/bin/python. Commands run as part of docker run or a CMD statement in a Dockerfile will be passed as arguments to python.
To access the shell in the python:latest-dev image, you'll need to include an --entrypoint option, as in the following example.
Also note that the python image uses the nonroot user by default. To perform operations such as installing packages with apk, run the image as root.
We recommend against using the root user in a production environment.
If you require additional packages that can be installed with the pip package manager, we recommend using a multistage build. This process involves installing packages in a virtual environment using the latest-dev variant, then copying this environment over to the minimal runtime image.
The following is a minimal example of a Dockerfile that uses a multistage build to run an app.py script after installing dependencies listed in a requirements.txt file.
For a more complete example, see Getting Started with the Python Chainguard Image on Chainguard Academy.
Chainguard's Python builds deviate from upstream Python in their TLS and hashlib defaults.
Chainguard OS doesn't support the deprecated TLS 1.1 and earlier protocol versions. However, a lot of Python software still uses the ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_1, and ssl.PROTOCOL_TLSv1_2 constants, which at one time were the way to opt in to a secure protocol version. Stock Python compiled against Chainguard Hardened OpenSSL doesn't provide these constants, so code that references them fails with an AttributeError.
To preserve source compatibility, Chainguard patches Python to always provide the legacy constants. They're aliases of ssl.PROTOCOL_TLS, so rather than pinning an old protocol version, connections negotiate TLS 1.3, or TLS 1.2 with peers that don't support TLS 1.3:
For the full list of protocol versions and ciphers available by default and as opt-ins, see OpenSSL 4.0 in Chainguard OS.
The Python hashlib module offers many digests. Some of them, such as MD5 and SHA-1, are considered weak, but all of them are available by default. Each digest constructor accepts an optional usedforsecurity keyword argument, which defaults to True.
Chainguard provides a set of python-hardened packages that block weak digests at different levels when they're used for security purposes. Add one of these packages to the image with Custom Assembly to enforce the hash digest policy appropriate for your organization. The packages conflict with each other, so install only one.
| Package to add | md5 | sha1 | sha224 | sha256 | sha384 |
|---|---|---|---|---|---|
None (default) | ✅ | ✅ | ✅ | ✅ | ✅ |
| 🚫 | ✅ | ✅ | ✅ | ✅ |
| 🚫 | 🚫 | ✅ | ✅ | ✅ |
| 🚫 | 🚫 | 🚫 | ✅ | ✅ |
| 🚫 | 🚫 | 🚫 | 🚫 | ✅ |
✅ allowed, 🚫 blocked unless called with usedforsecurity=False.
Blocked digests are also refused by hashlib.new(), including OpenSSL aliases such as SHA-1 and SHA2-256. HMAC (hmac.new(), hmac.HMAC, and hmac.digest()) and hashlib.pbkdf2_hmac() take no usedforsecurity argument, because any use of them is for security, so they always refuse blocked digests.
When planning for post-quantum cryptography (PQC) safety, note that quantum algorithms in theory significantly reduce the effort of attacks on hash functions. Grover's algorithm reduces the effort of a preimage attack on an n-bit digest from 2<sup>n</sup> to 2<sup>n/2</sup> operations, and the Brassard, Høyer, and Tapp (BHT) algorithm reduces the effort of a collision attack from 2<sup>n/2</sup> to 2<sup>n/3</sup> operations. Carefully evaluate the security considerations of existing digest usage in your applications.
A blocked digest raises a ValueError:
A significant portion of the Python ecosystem uses these digests for non-security purposes without declaring usedforsecurity=False. For this reason, no hardened hashlib configuration can support all Python applications. For example:
pip uses SHA-224 to name the files in its cache.Test your application with the chosen python-hardened package before deploying it to production.
Tags with an -ossl35 suffix include a hardened build of OpenSSL 3.5. These tags provide the OpenSSL 3 libraries (libssl.so.3 and libcrypto.so.3) for applications that have not moved to OpenSSL 4. To pull one, run the following command:
This image is also available as a Chainguard VM, available to deploy on Amazon AWS EC2, Google Cloud Compute Engine, Microsoft Azure and On-Prem through VMware, KVM and QEMU virtualization. Complete our registration form to get access to Chainguard VMs and try it out for yourself.
Chainguard's free tier of Starter container images are built with Wolfi, our minimal Linux undistro.
All other Chainguard Containers are built with Chainguard OS, Chainguard's minimal Linux operating system designed to produce container images that meet the requirements of a more secure software supply chain.
The main features of Chainguard Containers include:
For cases where you need container images with shells and package managers to build or debug, most Chainguard Containers come paired with a development, or -dev, variant.
In all other cases, including Chainguard Containers tagged as :latest or with a specific version number, the container images include only an open-source application and its runtime dependencies. These minimal container images typically do not contain a shell or package manager.
Although the -dev container image variants have similar security features as their more minimal versions, they include additional software that is typically not necessary in production environments. We recommend using multi-stage builds to copy artifacts from the -dev variant into a more minimal production image.
To improve security, Chainguard Containers include only essential dependencies. Need more packages? Chainguard customers can use Custom Assembly to add packages, either through the Console, chainctl, or API.
To use Custom Assembly in the Chainguard Console: navigate to the image you'd like to customize in your Organization's list of images, and click on the Customize image button at the top of the page.
Refer to our Chainguard Containers documentation on Chainguard Academy. Chainguard also offers VMs and Libraries — contact us for access.
This software listing is packaged by Chainguard. The trademarks set forth in this offering are owned by their respective companies, and use of them does not imply any affiliation, sponsorship, or endorsement by such companies.
Chainguard's container images contain software packages that are direct or transitive dependencies. The following licenses were found in the "latest" tag of this image:
BSD-2-Clause
GCC-exception-3.1
GPL-2.0-only
GPL-3.0-or-later
MIT
For a complete list of licenses, please refer to this Image's SBOM.
Software license agreementChainguard Containers are SLSA Level 3 compliant with detailed metadata and documentation about how it was built. We generate build provenance and a Software Bill of Materials (SBOM) for each release, with complete visibility into the software supply chain.
SLSA compliance at ChainguardThis image helps reduce time and effort in establishing PCI DSS 4.0 compliance with low-to-no CVEs.
PCI DSS at ChainguardA FIPS validated version of this image is available for FedRAMP compliance. STIG is included with FIPS image.
Image contains multiple maintained release tracks and is eligible for end of life support.