anagilla
Databricks Employee
Databricks Employee

This is by design: Can Run always includes viewing the cells.

Notebook access has a single view-only level (labeled CAN VIEW in the UI, CAN READ in the Permissions API) that sits below Can Run, and %run and notebook workflows execute at that view-only level. So anyone who can run the notebook can read it, and ACLs cannot grant execution while hiding the code.

To protect the sensitive parts, move them out of the notebook:

  1. Put credentials in a secret scope and read them with dbutils.secrets.get(). Redaction is best effort (literal values only, and not applied to the Spark driver's stdout/stderr), so also limit who can run the notebook.

  2. Move shared logic into a library or wheel, or a Unity Catalog function with EXECUTE granted, so callers use it without seeing the source.

  3. Run the sensitive work through a job or service principal, so users trigger it without opening the notebook.