How to run Jupyter notebooks on awx, from any browser
Run JupyterLab on your own awx computer and open it from a laptop, a lab PC or a tablet. It keeps running when you close the tab, comes back by itself after the computer sleeps, and your notebooks stay where you left them. Here is a real run on a Small computer.
At a glance. Install JupyterLab in a Python environment (42 seconds on a Small computer), set a password, add a short settings file, run it as an awx service, and open it through a link. Everything below is typed in the computer’s Terminal tab, except two forms on the Links tab.
Step 1: install JupyterLab
Every awx computer has Python 3.12. Put JupyterLab in its own environment in your home folder, with pandas and Matplotlib for the usual data work:
python3 -m venv ~/jlab
~/jlab/bin/pip install jupyterlab pandas matplotlib
mkdir -p ~/notebooks
On our Small computer (0.5 vCPU, 1 GiB of memory) this took 42 seconds and used 473 MB of disk. We got JupyterLab 4.6.6. The ~/notebooks folder is where your notebooks will live; you can see it on the Files tab too.
Step 2: set a password
Anyone with your link will reach the Jupyter page, so it needs a password:
~/jlab/bin/jupyter lab password
Type a password twice. Jupyter keeps only a hash of it, in ~/.jupyter/jupyter_server_config.json. Use a password you do not use anywhere else.
Step 3: tell Jupyter how it will be opened
Make a settings file, ~/.jupyter/jupyter_lab_config.py. The easiest way is nano ~/.jupyter/jupyter_lab_config.py, then paste:
c = get_config() # noqa
c.ServerApp.ip = "0.0.0.0"
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.root_dir = "/home/agent/notebooks"
c.ServerApp.allow_remote_access = True
c.ServerApp.allow_origin_pat = r"https://[a-z0-9-]+\.awanbox\.com"
Line by line: Jupyter listens on port 8888 so that a link can reach it, does not try to open a browser on the computer, and shows your notebooks folder. The last line matters most. Jupyter checks the address of the page that talks to it, and refuses anything it does not recognise; this line says that addresses on awanbox.com, the share links and custom names, are yours. Without it, logging in ends on a page that says 404 : Not Found.
If you will open it on your own domain, add that too, for example r"https://(([a-z0-9-]+\.awanbox\.com)|(notebooks\.example\.org))".
Step 4: keep it running
Started in the Terminal tab, Jupyter would stop when you close it. Run it as an awx service instead: open the computer’s Links tab, then Services, and fill in:
| Field | What to type |
|---|---|
| Name | jupyter |
| Command | /home/agent/jlab/bin/jupyter lab |
| Port (optional) | 8888 |
Press Add service. A service is started again a few seconds after it stops, and again whenever the computer starts. Its Log button shows what Jupyter prints, which is the first place to look if something goes wrong.
Step 5: open it from any browser
Still on the Links tab, choose Links, type port 8888, pick how long the link should work (up to 7 days) and press Create link. You get an address like https://a1b2c3….awanbox.com. Open it, and Jupyter asks for your password:
For an address that does not expire, use Custom names on the same tab instead, for example yourname-notebooks.awanbox.com. It costs RM1 of credit once and stays until you remove it.
Step 6: run a notebook
We made a small notebook with 30 made-up quiz marks: a table, a summary and a histogram. Kernel, Restart Kernel and Run All Cells ran it from the top, through the link, in a few seconds:
Save with Ctrl+S as usual. The notebook is a file on the computer, in ~/notebooks, so you can also download it from the Files tab or put it in Git.
After the computer sleeps
A computer with nobody working on it goes to sleep after a while. We stopped ours and started it again to see what happens: Jupyter answered again 7 seconds after the start, without us doing anything, and the notebook still had all three results. Open the same link (or your custom name) and log in again.
To keep it awake while you are away, see Why a computer sleeps and how to keep it running.
Good to know
- Small is enough for pandas, Matplotlib and course-sized data. Choose Large for big data frames or models; see Small or Large.
- The link is public, the notebook is not. Anyone with the link sees the password page, so keep the password to yourself. Remove the link on the Links tab when you are done with it.
- A terminal is in Jupyter too. File, New, Terminal opens one on the same computer.
- More packages:
~/jlab/bin/pip install scikit-learn, then restart the kernel. - For a class, each student does this on their own computer, so nobody’s notebooks or packages get in the way of anybody else’s.
Keep reading
- Clean and analyse a survey CSV with Python
- Python and Linux with a tutor beside you
- Run a script every morning without your laptop
Getting started
Sign in with your Google account, give your name and confirm your email. New accounts are approved by hand, and you start on the Free plan. See Pricing for what the paid plan includes.
Awi, signing off.