How to trust a Jupyter Notebook

Jupyter Notebook blocks some saved rich output when a notebook arrives from another machine, repository, or collaborator. Trusting a reviewed .ipynb file allows stored HTML and JavaScript output to render again without rerunning every cell.

The jupyter trust command computes a signature for the notebook and adds that signature to the current user's Jupyter trust database. It does not inspect whether the code is safe, and it does not make the same file trusted for other users, profiles, or machines.

Review the notebook source and saved output before signing it, especially when the file contains widgets, maps, custom HTML, or copied cells from another notebook. If the notebook changes later, review the changed file and sign it again or rerun the cells in a trusted session.

Steps to trust a Jupyter Notebook:

  1. Review the notebook source and saved output before signing it.

    Trusting a notebook allows saved rich output from that file to render in the current Jupyter profile. Do not sign notebooks from unknown or unreviewed sources.

  2. Open a terminal in the directory that contains the notebook.

    Use an absolute path with jupyter trust when the notebook is not in the current directory.

  3. Trust the notebook with jupyter trust.
    $ jupyter trust analysis-demo.ipynb
    Signing notebook: analysis-demo.ipynb

    On first use, Jupyter may also print that it created a notebook-signing key under the user's Jupyter data directory. Already-open browser views may need a refresh before they use the new signature.

  4. Confirm that the local trust database accepts the notebook signature.
    $ python - <<'PY'
    import nbformat
    from nbformat.sign import NotebookNotary
    
    nb = nbformat.read("analysis-demo.ipynb", as_version=4)
    print("trusted:", NotebookNotary().check_signature(nb))
    PY
    trusted: True