docs/examples/development/jupyterlab.mdx
<Tooltip tip="This example publishes JupyterLab to a port on the computer running the CLI, which is not available on microsandbox cloud."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>
This example installs JupyterLab into a Python microVM, stores notebooks in a named volume, and exposes the server only on host loopback.
Set a temporary token in the host shell:
<CodeGroup> ```sh macOS & Linux export JUPYTER_TOKEN="$(openssl rand -hex 24)" ```$bytes = New-Object byte[] 24
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
$rng.Dispose()
$env:JUPYTER_TOKEN = -join ($bytes | ForEach-Object { $_.ToString('x2') })
Start the server:
<CodeGroup> ```sh macOS & Linux msb run -d --name jupyter-demo --replace \ --cpus 2 --memory 2G --root-disk 4G \ -p 127.0.0.1:8888:8888 \ -e JUPYTER_TOKEN="$JUPYTER_TOKEN" \ --mount-named jupyter-notebooks:/workspace \ --workdir /workspace \ python:3.13-slim -- sh -lc ' pip install --no-cache-dir jupyterlab==4.6.2 && exec jupyter lab \ --ip=0.0.0.0 \ --port=8888 \ --no-browser \ --allow-root \ --IdentityProvider.token="$JUPYTER_TOKEN" ' ```msb run -d --name jupyter-demo --replace `
--cpus 2 --memory 2G --root-disk 4G `
-p 127.0.0.1:8888:8888 `
-e "JUPYTER_TOKEN=$env:JUPYTER_TOKEN" `
--mount-named jupyter-notebooks:/workspace `
--workdir /workspace `
python:3.13-slim -- sh -lc '
pip install --no-cache-dir jupyterlab==4.6.2 &&
exec jupyter lab \
--ip=0.0.0.0 \
--port=8888 \
--no-browser \
--allow-root \
--IdentityProvider.token="$JUPYTER_TOKEN"
'
Open http://127.0.0.1:8888/lab?token=<token> in your browser and replace <token> with the value generated above.
Check the authenticated API from the host:
<CodeGroup> ```sh macOS & Linux curl -sS "http://127.0.0.1:8888/api?token=$JUPYTER_TOKEN" | head ```curl.exe -sS "http://127.0.0.1:8888/api?token=$env:JUPYTER_TOKEN" | Select-Object -First 10
Then inspect the recent server output:
msb logs --tail 20 jupyter-demo
The logs show Jupyter Server listening on guest port 8888. Notebooks saved under /workspace remain in jupyter-notebooks after the sandbox is removed.
Remove the sandbox:
msb rm -f jupyter-demo
Remove persisted notebooks only when you no longer need them:
msb volume rm jupyter-notebooks
Clear the token from the host shell:
<CodeGroup> ```sh macOS & Linux unset JUPYTER_TOKEN ```Remove-Item Env:JUPYTER_TOKEN
Keep jupyter-notebooks if you want to retain the notebooks.