Using secrets in Notebooks in Workspaces¶
Secret support in workspace notebooks¶
Snowflake notebooks running in Workspaces can use secret objects together with external access integrations (EAIs) so that credentials never appear as literals in notebook code. You configure secrets and EAIs in SQL (for example, in a worksheet); you then attach them to the notebook service, scheduler, or EXECUTE NOTEBOOK PROJECT call.
Prerequisites: setting up secrets and external access¶
Before you can use secrets inside a Snowflake notebook, configure the underlying security objects and network rules. These steps are performed outside of the notebook (for example, in a Snowflake worksheet).
Documentation links¶
For detailed configuration options and security workflows, see:
CREATE SECRET (secret types, syntax, and examples)
External network access overview (external access integrations and network rules)
SYSTEM$START_OAUTH_FLOW and SYSTEM$FINISH_OAUTH_FLOW (manual OAuth authorization flow)
External network access examples (OAuth examples with EAIs)
Set up external access for Snowflake Notebooks (notebook patterns for external APIs, including GitHub)
Basic secret setup¶
To use existing secrets, run SHOW SECRETS (for example, SHOW SECRETS IN ACCOUNT;). To create a new secret,
use CREATE SECRET.
Note
Replace SNOWPUBLIC and NOTEBOOKS in the examples with your database and schema.
Other common secret types include:
PASSWORD, which requires bothUSERNAMEandPASSWORD.OAUTH2, used for integrations with external providers (for example, GitHub).
External access integration (EAI)¶
To allow a notebook to use secrets when calling the public internet, connect a network rule and an external access integration.
Advanced authentication (OAuth)¶
For OAuth-based providers, create a security integration and complete the manual OAuth flow using SYSTEM$START_OAUTH_FLOW (and SYSTEM$FINISH_OAUTH_FLOW in the same session). That flow lets Snowflake exchange tokens with the external provider. For end-to-end examples, see External network access examples and Set up external access for Snowflake Notebooks.
Notebook service integration with secrets¶
You can select secrets in the notebook create, edit, and scheduler dialogs.
In the navigation menu, select Projects » Workspaces.
Open Notebooks, then start Create service (or edit an existing service).
In Service settings, attach an external access integration and select one or more secrets from the drop-down. You can attach multiple secrets.
Verify the service starts successfully, then use Python cells to read secrets with the Snowpark secrets API or from the mount paths shown in the following examples.
Note
If the fully qualified secret name contains special characters (for example, SNOWPUBLIC.NOTEBOOKS."my secret 1"), Snowflake normalizes the path
used in Python and in the container. Hyphens, spaces, and similar characters in the secret name segment become underscores. Database and schema
segments are case-insensitive.
Example: SNOWPUBLIC.NOTEBOOKS."my secret 1" is exposed to Python helpers as snowpublic/notebooks/my_secret_1 (adjust database and schema
to match where the secret is stored).
The secret files are mounted under /secrets/ inside the Snowflake-provided container. For example, a generic string secret might appear at:
/secrets/snowpublic/notebooks/my_secret_1/secret_string
Replace snowpublic and notebooks with the database and schema that own your secrets. Database, schema, and secret name matching is case-insensitive.
The Snowpark library exposes different helpers for each secret type, as shown below.
Calling GENERIC_STRING secrets from a Python cell¶
Calling PASSWORD secrets from a Python cell¶
Calling OAUTH2 secrets from a Python cell¶
Replace _/_/github_secret with the normalized path for your OAuth2 secret (database/schema/name), following the same rules as above.
Scheduling notebooks with secrets¶
When you schedule a notebook from Snowsight, add the EAIs and secrets the scheduled task should use in the scheduling dialog so the headless run inherits the same external access and credentials as interactive development.
Non-interactive runs with EXECUTE NOTEBOOK PROJECT and secrets¶
Headless runs must list both EAIs and secrets when the notebook depends on them. Pass integrations with EXTERNAL_ACCESS_INTEGRATIONS and pass secrets
with SECRETS. For full syntax, see EXECUTE NOTEBOOK PROJECT.
Replace the placeholders with the integrations and fully qualified secrets your notebook requires.