> ## Documentation Index
> Fetch the complete documentation index at: https://docs.microsandbox.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# JupyterLab

> Run token-authenticated notebooks in an isolated Python environment

Local-only (This guide publishes JupyterLab to a port on the computer running the CLI, which is not available on microsandbox cloud.)

This guide installs JupyterLab into a Python microVM, stores notebooks on a sized root disk, and exposes the server only on host loopback.

## Run JupyterLab

**1. Start JupyterLab**

Set a temporary token in the host shell:

```sh macOS & Linux theme={null}
export JUPYTER_TOKEN="$(openssl rand -hex 24)"
```

```powershell Windows theme={null}
$bytes = New-Object byte[] 24
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
$rng.Dispose()
$env:JUPYTER_TOKEN = -join ($bytes | ForEach-Object { $_.ToString('x2') })
```

Create a startup script for the guest:

```sh start-jupyter.sh theme={null}
#!/bin/sh
set -eu

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"
```

Start the server:

```sh macOS & Linux theme={null}
msb run -d --name jupyter-demo --replace \
  --cpus 2 --memory 2G --root-disk 6G \
  -p 127.0.0.1:8888:8888 \
  -e JUPYTER_TOKEN="$JUPYTER_TOKEN" \
  --mkdir /workspace \
  --workdir /workspace \
  --script-path start-jupyter:./start-jupyter.sh \
  --entrypoint start-jupyter \
  python:3.13-slim
```

```powershell Windows theme={null}
msb run -d --name jupyter-demo --replace `
  --cpus 2 --memory 2G --root-disk 6G `
  -p 127.0.0.1:8888:8888 `
  -e "JUPYTER_TOKEN=$env:JUPYTER_TOKEN" `
  --mkdir /workspace `
  --workdir /workspace `
  --script-path start-jupyter:./start-jupyter.sh `
  --entrypoint start-jupyter `
  python:3.13-slim
```

Open `http://127.0.0.1:8888/lab?token=<token>` in your browser and replace `<token>` with the value generated above.

**2. Verify the service**

Check the authenticated API from the host:

```sh macOS & Linux theme={null}
curl -sS "http://127.0.0.1:8888/api?token=$JUPYTER_TOKEN" | head
```

```powershell Windows theme={null}
curl.exe -sS "http://127.0.0.1:8888/api?token=$env:JUPYTER_TOKEN" | Select-Object -First 10
```

Then inspect the recent server output:

```sh Shell theme={null}
msb logs --tail 20 jupyter-demo
```

The logs show Jupyter Server listening on guest port 8888. Notebooks saved under `/workspace` remain on the root disk when the sandbox stops and starts.

> [!WARNING]
>
> The token is visible to the guest and to processes that can inspect the host command environment. Use the [secrets workflow](https://docs.microsandbox.dev/sandboxes/secrets.md) for production credentials, retain the loopback bind, and place a TLS-terminating authenticated proxy in front of any remote deployment.

**3. Clean up**

Remove the sandbox:

```sh Shell theme={null}
msb rm -f jupyter-demo
```

Clear the token from the host shell:

```sh macOS & Linux theme={null}
rm -f start-jupyter.sh
unset JUPYTER_TOKEN
```

```powershell Windows theme={null}
Remove-Item start-jupyter.sh
Remove-Item Env:JUPYTER_TOKEN
```

Copy any notebooks you want to keep to the host before removing the sandbox.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.