Custom Runtime Images¶
Custom runtime images let you use your own container images for machine learning workloads on Container Runtime, including Snowflake Notebooks and ML Jobs. You can extend the Snowflake-provided base images provided they meet platform compatibility requirements.
Overview¶
While the Container Runtime image is convenient for interactive use with Notebooks and ad-hoc execution with ML Jobs, using only the Snowflake-provided image can create challenges for enterprise customers, particularly those in regulated industries or with mature MLOps practices.
Custom runtime images address the following needs:
-
Compliance and security: Strict IT and security policies often mandate the use of pre-scanned and allowlisted images for production ML pipelines. Custom images let regulated customers integrate fully security-scanned and approved images into Snowflake workloads.
-
CI/CD integration: Custom images can be built, tested, scanned, and validated as part of existing CI/CD pipelines, enabling automated validation and faster iteration when deploying to Snowflake.
-
Reproducibility: Data scientists can create consistent Docker images that encapsulate exact package and version requirements, ensuring reproducibility across development, staging, and production environments.
-
Package control: Organizations that don’t have external access integrations to PyPI repositories can use org-approved and managed images without needing PyPI access at runtime.
-
Persistent environments: Custom images eliminate the need for manual
pip installcommands in every Notebook session, providing persistent package installations that are shareable and reproducible across Notebooks.
How it works¶
You can create custom images by extending the base image: Build on one of the Snowflake-provided base ML runtime images, adding your own packages and configuration on top.
After building a custom image, you push it to a Snowflake image repository, validate it, and register it as a Custom Runtime Environment (CRE). You can then reference the CRE when running ML Jobs or Notebooks.
Workflow: Create and use a custom runtime image¶
To use a Custom Runtime Environment in ML Jobs or Notebooks, you need to build a custom container image, validate it, push it to Snowflake, and register it. The following steps outline the complete end-to-end workflow. Before you begin, make sure to install Snowflake CLI.
Step 1: Authenticate with the image registry¶
Before pulling the base image or pushing to the Snowflake repository, authenticate the local Docker client with the Snowflake image registry using the Snowflake CLI.
For more information, see snow spcs image-registry login.
Step 2: Select and pull a base image¶
All custom images must be derived from an official Snowflake ML runtime base image. Base images are specific to the hardware type (CPU or GPU) and Python version.
- Identify the appropriate base image from the Container Runtime releases.
- Pull the base image locally using Docker.
Step 3: Author the Dockerfile¶
Create a Dockerfile that uses the selected Snowflake base image. Specify any additional system packages, Python libraries, or organizational configuration required for your workloads.
Step 4: Build the custom image¶
Build the custom image locally using standard Docker tooling. Build for the linux/amd64 platform to ensure
compatibility with Snowflake’s execution environment.
Step 5: Validate the image locally (pre-push)¶
Before pushing the image to Snowflake, validate it locally to ensure it meets runtime requirements. This advisory step helps prevent failures during the server-side registration process.
Resolve any missing dependencies, conflicting packages, or configuration errors flagged by the validation report.
Validation requirements¶
To pass the local validation, your image must meet the following criteria:
- Entrypoint: The image must use the exact entrypoint path
/usr/local/bin/entrypoint.sh. - Required environment variables: The image must expose the dashboard port by including the environment
variable
DASHBOARD_PORT=12003. - Mandatory Python packages: The image must contain the following packages:
- snowflake-ml-python
- snowflake-snowpark-python[pandas]
- ray
- jupyter-server
- notebook
- ipykernel
- ipython
- sqlparse
- jinja2
- psutil
- Healthy package dependencies: The Python environment must have a fully resolved dependency tree with no package conflicts.
- Optional vulnerability scanning: The validation tool can also scan for vulnerabilities (CVEs) in your image’s packages or base layers. While fixing high-severity vulnerabilities is strongly recommended, this check isn’t required to pass validation.
Step 6: Tag and push to the image repository¶
Tag the locally built, validated image with the fully qualified URL of the Snowflake image repository, then push it.
-
Tag the image:
-
Push the image:
The registry_url will look something like <your_account>.registry.snowflakecomputing.com.
Step 7: Create the Custom Runtime Environment¶
With the image stored in the Snowflake repository, run the DDL command to register the Custom Runtime Environment. During this step, Snowflake performs a server-side validation check to confirm the image executes correctly. The CRE is only created if this check passes.
Once this command completes successfully, the Custom Runtime Environment is in the RESOLVED state and is ready to be referenced in ML Jobs and Notebooks.
Use custom runtime images in ML Jobs¶
Once your custom image is registered, you can use it to run ML Jobs. This ensures your code executes in your specialized environment with all your required dependencies.
When submitting an ML Job using the Snowflake ML Python SDK, configure the environment using the
runtime_environment parameter. Reference an admin-approved Custom Runtime Environment using the cre@<name> format.
Prerequisites¶
- Required package: snowflake-ml-python version 1.37.0 or higher.
- Role privileges: The active role must hold the USAGE privilege on the target Custom Runtime Environment, along with access to the underlying image repository.
- Environment status: The Custom Runtime Environment must be in the RESOLVED state. Environments marked as DEPRECATED can’t be used for new jobs.
Usage notes¶
- When using a CRE alias, the system verifies the image’s SHA digest at runtime. If the underlying image in the repository was modified after the CRE was registered, the job submission is rejected to ensure reproducibility. In this case, you must recreate the CRE.
Example¶
Use custom runtime images in Notebooks¶
Once your custom image is registered, you can use it to run Notebook services. This ensures your code executes in your specialized environment with all your required dependencies.
Registered custom images can be selected from advanced settings when creating, editing, and scheduling a
notebook in the workspaces UI. You can also use a custom image when executing a notebook project using SQL with the
RUNTIME parameter. Reference an admin-approved Custom Runtime Environment using the cre@<name> format.
Prerequisites¶
- Role privileges: The active role must hold the USAGE privilege on the target Custom Runtime Environment, along with access to the underlying image repository.
- Environment status: The Custom Runtime Environment must be in the RESOLVED state. Environments marked as DEPRECATED can’t be used for new Notebooks.
Usage notes¶
- When using a CRE alias, the system verifies the image’s SHA digest at runtime. If the underlying image in the repository was modified after the CRE was registered, the service submission is rejected to ensure reproducibility. In this case, you must recreate the CRE.
Example¶
Custom Runtime Environments SQL reference¶
A Custom Runtime Environment (CRE) is a Snowflake object that references a custom container image stored in an SPCS image repository. Use the following SQL commands to create, modify, view, and delete custom runtime environments.
CREATE CUSTOM RUNTIME ENVIRONMENT¶
Creates a new custom runtime environment in your account.
Syntax¶
Required parameters¶
name
String that specifies the identifier (the name) for the custom runtime environment; it must be unique for your account. Quoted names for special characters or case-sensitive names aren’t supported.
IMAGE_PATH = ‘<image_path>’
Specifies the logical path to the image in the Snowflake image repository (for example,
'/db/schema/repo/image:tag').
BASE_IMAGE_TYPE = { CPU | GPU }
Specifies the hardware optimization of the image. This must match the hardware requirements of the base image used to build the custom image.
Access control requirements¶
| Privilege | Object |
|---|---|
| Create Custom Runtime Environment | Account |
Usage notes¶
- Executing this command triggers an automated server-side validation job. If the validation fails, the custom runtime environment isn’t created.
- To avoid failures during creation, validate your image locally using client-side validation before running this command. See Client-side image validation.
- All custom images must be derived from an official Snowflake ML base image.
Examples¶
ALTER CUSTOM RUNTIME ENVIRONMENT¶
Updates the lifecycle status of an existing custom runtime environment.
Syntax¶
Parameters¶
name
Specifies the identifier for the custom runtime environment to alter. Quoted names for special characters or case-sensitive names aren’t supported.
CRE_STATUS = { RESOLVED | DEPRECATED }
Updates the availability of the environment.
- RESOLVED: The environment is active and can be used in ML Jobs or Notebooks.
- DEPRECATED: The environment remains visible but can no longer be used for new ML Job submissions or Notebooks.
Access control requirements¶
| Privilege | Object |
|---|---|
| MODIFY | Custom Runtime Environment |
Examples¶
DESCRIBE CUSTOM RUNTIME ENVIRONMENT¶
Retrieves detailed information about a specific custom runtime environment.
Syntax¶
Parameters¶
name
Specifies the identifier for the custom runtime environment to describe. Quoted names for special characters or case-sensitive names aren’t supported.
Output¶
| Column | Description |
|---|---|
| name | Custom runtime environment name. |
| image_name | Image name. |
| tag | Image tag. |
| digest | SHA256 digest of the image. |
| created_on | Date and time when the custom runtime environment was created. |
| updated_on | Date and time when the custom runtime environment was last updated using ALTER CUSTOM RUNTIME ENVIRONMENT. |
| owner | Role that owns the custom runtime environment. |
| cre_status | State of the custom runtime environment. |
| base_image_type | The hardware type (CPU or GPU). |
| image | Image path in the image repository. |
Access control requirements¶
| Privilege | Object |
|---|---|
| MONITOR | Custom Runtime Environment |
Examples¶
SHOW CUSTOM RUNTIME ENVIRONMENTS¶
Lists the custom runtime environments that you have access to.
Syntax¶
Output¶
| Column | Description |
|---|---|
| name | Custom runtime environment name. |
| image_name | Image name. |
| tag | Image tag. |
| digest | SHA256 digest of the image. |
| created_on | Date and time when the custom runtime environment was created. |
| updated_on | Date and time when the custom runtime environment was last updated using ALTER CUSTOM RUNTIME ENVIRONMENT. |
| owner | Role that owns the custom runtime environment. |
| cre_status | State of the custom runtime environment. |
| base_image_type | The hardware type (CPU or GPU). |
| image | Image path in the image repository. |
Access control requirements¶
| Privilege | Object |
|---|---|
| Any one of: OWNERSHIP, USAGE, or MONITOR | Custom Runtime Environment |
Usage notes¶
- The command only returns objects for which the current role has been granted at least one access privilege.
- The command returns a maximum of 10,000 records for the specified object type, as dictated by the access privileges for the role used to execute the command. Records above the 10,000-record limit aren’t returned, even with a filter applied.
Examples¶
DROP CUSTOM RUNTIME ENVIRONMENT¶
Removes a custom runtime environment from the account.
Syntax¶
Parameters¶
name
Specifies the identifier for the custom runtime environment to drop. Quoted names for special characters or case-sensitive names aren’t supported.
Access control requirements¶
| Privilege | Object |
|---|---|
| OWNERSHIP | Custom Runtime Environment |
Usage notes¶
- Dropping a custom runtime environment only removes the Snowflake metadata object. The actual underlying container image remains in your SPCS image repository.
- When the IF EXISTS clause is specified and the target object doesn’t exist, the command completes successfully without returning an error.