EXECUTE CODE BUNDLE¶
Note
Notebook Project Objects have been renamed to Code Bundles. The NOTEBOOK PROJECT grammar is still supported; for that syntax, see EXECUTE NOTEBOOK PROJECT. For background on the rename, see the behavior change announcement.
Executes a Code Bundle at the specified entrypoint. This command runs the code in a non-interactive (headless) mode and is useful for CI/CD pipelines and other orchestrated workflows where you want to pass parameters or lock dependency versions for repeatable runs. The command can be run from:
- SQL files.
- Other Snowflake executables (Tasks).
- External orchestrators that issue SQL (for example, Airflow, Prefect, Dagster, CI/CD systems).
The compute type, runtime, dependencies, external access integrations, and secrets are defined in the Code Bundle’s code_bundle.yml specification. You can override the stored specification at run time with the WITH SPECIFICATION clause.
Important
Before triggering a non-interactive run of a notebook, ensure that your notebook sets its execution context (database and schema) or uses fully qualified object names. For more information, see Editing and running notebooks in Workspaces.
See also: CREATE CODE BUNDLE, SHOW CODE BUNDLES, CREATE TASK, CI/CD workflow scenario, Observability and logging for Notebooks in Workspaces, Running notebooks with parameters, Using secrets in Notebooks in Workspaces
Syntax¶
Required parameters¶
nameIdentifier of the Code Bundle to execute.
Must reference an existing Code Bundle created with CREATE CODE BUNDLE.
Must be fully qualified unless it resides in the current DATABASE and SCHEMA.
For more information, see Identifier requirements.
ENTRYPOINT = 'path'Specifies the file within the bundle that Snowflake executes (for example,
main.pyornotebooks/train.ipynb).The path is relative to the bundle root.
.ipynbnotebook files run only on compute pools (Container Runtime).
Optional parameters¶
ARGUMENTS = ( 'arg' [ , 'arg' ... ] )Optionally passes one or more string arguments to the entrypoint at runtime, which appear as command-line arguments in the
sys.argvlist. Arguments are useful for making logic dynamic (for example, selecting an environment such as--env prod).Specify each argument as a separate quoted string in the list. In a Python entrypoint, access the arguments using
sys.argv[0]for the entrypoint name,sys.argv[1]for the first argument, and so on.Only strings are supported; other data types (such as integers or Booleans) are interpreted as NULL.
Examples:
WITH SPECIFICATION $$ yaml_spec $$Optionally provides an inline
code_bundle.ymlspecification that overrides the specification stored with the Code Bundle. This is useful for testing different configurations (for example, a different compute type or runtime version) without modifying the bundle.Example:
Access control requirements¶
The role executing EXECUTE CODE BUNDLE must have either OWNERSHIP or USAGE privileges on the Code Bundle.
If the Code Bundle is configured to run on compute pools (compute_type: compute_pool), the executing role must also have:
- USAGE and MONITOR on the query warehouse.
- USAGE or OWNERSHIP on the compute pool and on the database and schema containing the Code Bundle.
- READ or OWNERSHIP on any secrets referenced in the specification. USAGE on a secret is not sufficient.
- USAGE or OWNERSHIP on the external access integrations, artifact repositories, and other objects referenced in the specification.
For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.
For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
Usage notes¶
- You can’t run the
EXECUTE CODE BUNDLEcommand from a notebook cell. - You can call
EXECUTE CODE BUNDLEfrom tasks, enabling runs as part of larger workflows. - Run history and run result visibility for executions triggered by this command depends on the viewing role’s Code Bundle privileges and
IMPERSONATEprivilege over the initiating user. For details, see Run history and result visibility.
Examples¶
Execute a Code Bundle:
Execute a Code Bundle with arguments:
Execute a notebook packaged in a Code Bundle (runs on a compute pool):