A Jupyter notebook is a document that mixes code, results and notes, served by a program that runs any code.
This guide is for data analysts, students and new security staff who use or look after notebooks. You do not need to code to follow it.
In short
- Anyone who can reach a running Jupyter server and get past its sign-in can run code on that computer.
- Keep the server on your own machine, with its token turned on.
- Notebooks save the results of each cell, so a printed API key stays in the file.
- Strip outputs before sharing or committing a notebook, and never type secrets into cells.
What you will learn
- Explain why an exposed notebook server is so dangerous.
- Spot where secrets hide inside a notebook file.
- Keep notebook outputs out of Git.
- Run a short safety check on your own notebooks this week.
- Notebook
- a file that holds code cells, their results and written notes.
- Engine (kernel)
- the program behind the notebook that actually runs your code.
- Sign-in code (token)
- a long random string the server asks for before it lets you in.
What is a Jupyter notebook?
Think of a lab notebook where every experiment is written down next to its result. A Jupyter notebook works the same way. You write a little code in a cell, run it, and the answer appears just below.
Behind the page sits a web server. Your browser talks to it, and the server passes your code to a kernel to run. The Jupyter Server docs say kernel or terminal access generally means running any code. They treat it as equal to all other permissions [1].
The notebook file itself is plain JSON text. Each code cell keeps its source code together with the outputs it produced when it ran [3].
Where the comparison stops working: a paper lab book cannot do anything. A notebook server can run any program, read files and use any cloud keys stored on the machine.
Why does it matter?
Notebooks are where data, code and keys meet. A small slip can expose all three.
If you are a data analyst or student
What could happen: you print a database password to test a connection, and the saved output goes to a shared folder.
Check this: search your notebooks for keys and passwords in outputs, not just in code.
If you run a cloud server for your team
What could happen: a notebook server opened to the internet lets a stranger run code with the server's cloud permissions.
Check this: confirm the server listens only on localhost or sits behind proper sign-in.
If you are new to security work
What could happen: keys in old notebook commits stay readable in Git history long after the cell is cleaned.
Check this: treat every key found in a notebook as leaked, and replace it.
What does it look like?
Here is a cut-down piece of a notebook file. Open any notebook in a text editor and you will see something similar.
Example only. All values are made up.
{ "cell_type": "code",
"source": ["print(config)"], (1)
"outputs": [ { "output_type": "stream", (2)
"text": ["api_key = EXAMPLE-not-a-real-key-0000"] } (3)
] }
- The code in the cell. It looks harmless: it only prints a settings object.
- The saved result of running that cell. Notebook formats store outputs such as stream, display_data, execute_result and error [3].
- In a real file, this line would contain a working key that anyone reading the file could use.
Why this is risky: the code is clean, so a quick look at the cells misses the key sitting in the output.
The safer way: load keys from an environment variable or secrets store, never print them, and strip outputs before sharing.
How does it work?
- You start the server. By default Jupyter Server runs at 127.0.0.1:8888 and is reachable only from localhost, meaning your own machine [2].
- It asks for a token. Token sign-in is on by default. Empty token and password settings switch it off. The docs say not to do this unless another layer handles access [1].
- You run cells. The kernel runs your code with your account's rights, including any cloud or database keys it can read.
- Results are saved. Outputs are written into the notebook file next to the code [3].
- You share or commit. Whatever is in the file, outputs included, goes with it unless you strip it first.

Need remote access to your own machine? The Jupyter docs say to use a password with SSL. Reach the server over https://, not plain http:// [2]. They also say this public-server set-up is not meant for many users [2].
Notebook outputs can include HTML and JavaScript. Jupyter treats that output as untrusted when you open a notebook you did not run yourself, unless a stored signature matches [1].
A worked example
This story is made up to show the idea.
Otto Whitlock is a junior analyst at a small retailer. He builds a sales forecast in a notebook on a cloud server. To reach it from home, he changes the server to listen on all addresses and turns off the token, because typing it was annoying.
His notebook also prints the warehouse database settings, password included, to check the connection. He commits the notebook to the team's Git repository.
A colleague in security spots the open port in a weekly scan. Together they act. They turn the token back on and bind the server to localhost, and Otto connects through the company VPN. They treat the database password as leaked and replace it, then move it into the team's secrets store.
They add nbstripout to the repository. Its Git filter removes outputs from what Git sees when committing, while Otto's local copy keeps its results [4]. The old password is still in past commits, which is why replacing it came first.
It took one afternoon, and nothing had been misused. Otto learned that a notebook is two things at once: a server that can run anything, and a file that remembers everything it printed.
Myths and mistakes
| What people think | What is true |
|---|---|
| A notebook is just a document. | It is backed by a server that can run any code with your rights [1]. |
| Turning off the token is fine on a quick test server. | The docs advise against it unless another layer handles access [1]. Test servers get found too. |
| If the code cell is clean, the notebook is clean. | Outputs, including error tracebacks, are saved in the file as well [3]. |
| Deleting the key from the latest commit fixes the leak. | Past commits still hold it. Replace the key first. |
| Stripping outputs once is enough. | Set it up as a Git filter so it runs on every commit [4]. |
What can I do this week?
- Check how your notebook server starts. Confirm it listens on localhost and asks for a token.
- Open two of your notebooks in a text editor and search for "key", "token" and "password".
- Move any secret you find into an environment variable or secrets store, and replace it.
- Install an output-stripping Git filter in one repository you use.
- Read Environment Variables and .env Files for Beginners.
Checklist
- My notebook server listens on localhost unless I have a strong reason.
- Token or password sign-in is turned on.
- Remote access goes through a VPN, tunnel or managed service, over HTTPS.
- No secrets are typed into cells or printed in outputs.
- Outputs are stripped before notebooks reach Git or shared folders.
- Any key found in a notebook is treated as leaked and replaced.
- I only open notebooks from people and places I trust.
Common questions
Is it safe to run Jupyter on my laptop?
Running it on your own machine with the default localhost setting and the token on is the usual safe starting point. Risk rises when you open it to other computers or turn sign-in off.
Why are outputs a problem if I never typed the key in?
Code can print settings objects, environment variables or error messages that include secrets. The notebook saves that output with the file. Anyone who opens the file later, or reads it in Git, sees the secret too.
Does stripping outputs clean my Git history?
No. A stripping filter changes what Git sees from now on. Secrets in older commits stay there, so replace them first. Then ask whoever runs the repository about cleaning up the history, if that is needed.
Can someone else's notebook harm me?
Running its cells runs its code with your rights. Read the code before you run it. Treat notebooks from unknown sources like any other download, and open them where they cannot reach your keys.
Where next?
Ready for the detail? Read the practitioner guide: Jupyter Server Security Guide. It covers server settings, JupyterHub, logging and a hardening baseline.
Also useful:
Related NHI Mgmt Group resources: Non-Human Identities for Beginners, Leaked Secret Response for Beginners and AI Security for Beginners.
Key terms
- Jupyter Notebook
- An interactive computing environment that combines code, output and narrative in a single document.
- Kernel
- The engine that runs the code in a notebook. Access to it means the power to run any code.
- API key
- A static credential an application uses to call an API. Anyone holding it can use it.
- Secrets scanning
- Automated tooling that searches code and files for exposed keys, tokens and passwords.
- Secrets sprawl
- Credentials spreading in an uncontrolled way across code, files, notebooks and tools.
Sources and further reading
- Project Jupyter, "Security in the Jupyter Server", Jupyter Server documentation. https://jupyter-server.readthedocs.io/en/latest/operators/security.html (accessed 30 Nov 2026).
- Project Jupyter, "Running a public Jupyter Server", Jupyter Server documentation. https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html (accessed 30 Nov 2026).
- Project Jupyter, "The Notebook file format", nbformat documentation. https://nbformat.readthedocs.io/en/latest/format_description.html (accessed 30 Nov 2026).
- nbstripout project, "nbstripout", PyPI. https://pypi.org/project/nbstripout/ (accessed 30 Nov 2026).