Skip to content

Notebooks ​

A notebook is a hosted, Marimo-based interactive Python notebook backed by a Sail session. Where a session is a runtime you connect your own client to, a notebook provides both the editor and the runtime.

When to use a notebook ​

  • Exploratory Python + Spark in one place. You want to write PySpark and see results without wiring up a local client or managing tokens.
  • Team-managed exploration. Team Admins and Editors can manage the notebook runtime while the creator retains access to the editor.
  • Authoring before you productionize. Prototype a transform in a notebook, then run it as a job once it's stable. The job adds a schedule, versions, and run history.

When not to use one:

  • Connecting an external client (local PySpark or a service). Use a session; it exposes Spark Connect over gRPC for exactly that.

Prerequisites ​

  • A compute profile on a cluster whose Readiness is Ready. It defines the Sail pod the notebook runs on. The notebook kernel runs on its own node of the driver instance type, so results you collect into Python have the same memory as the driver. The node launches in the driver's availability zone when that zone has capacity.
  • (Optional) A runtime profile with the libraries, environment variables and catalogs the notebook needs. Its environment variables also reach the notebook kernel; see Environment variables and secrets.
  • A catalog if you want to query your tables (recommended). A notebook inherits the catalogs of its runtime profile, and can add its own or replace them. For S3-backed tables, the data must be in the network workspace bucket or in an external data target granted to the compute profile.

Notebook timing ​

A notebook uses a backing session with these clocks:

SettingValueWhat happens
Idle timeout30 minutes by default; 2 minutes to 8 hoursAn inactive notebook's backing session moves to Idle. Activity is the notebook being open in a browser, a request through the session proxy, or a running cell.
Idle close delay5 minutes by defaultThe idle session closes and the notebook stops. Opening the notebook during the delay keeps it. Notebook contents persist.
Maximum duration7 days per startThe notebook stops regardless of activity. Starting it again creates a new backing session and resets this clock. Organization settings can change this value. A platform node upgrade can end a notebook that has run longer than 48 hours.

Create a notebook ​

  1. Open Notebooks in the sidebar and click Create Notebook.
  2. Fill in:
    • Notebook name: e.g. daily-sales-analysis.
    • Team: who can access the notebook according to their team roles. Only the creating member can open the notebook editor.
    • Compute profile: the compute profile whose Sail pod backs the notebook. Pick an existing one or create a new one inline.
    • Runtime profile (optional): the runtime profile with the notebook's libraries, environment variables and catalogs. You can override its settings for this notebook.
    • Idle timeout (minutes): how long the notebook may remain inactive before its backing session becomes idle. See Notebook timing, or accept the default.
    • Start from a marimo file (optional): the notebook opens with the file's cells instead of an empty notebook. See Import and download the notebook file.
  3. Click Create notebook. The notebook starts in Stopped.

Start, open, and stop ​

A notebook has its own lifecycle, independent of the workload it runs:

StatusMeaning
StoppedNo Sail or Marimo pods are running
StartingThe platform is provisioning the Sail and Marimo pods
RunningFully active and ready to use
StoppingTearing the pods down
ErrorProvisioning or teardown failed; check the status message
  • Start provisions the pods and moves the notebook to Running. Each start takes the workload profiles as they are then; see Settings of a notebook.
  • Open launches the Marimo editor against the running notebook.
  • Stop tears the pods down to reclaim compute. Saved notebook contents persist. Generated files in hosted notebooks do not. See Save and download generated files.

The platform saves notebook contents to the network's workspace bucket under notebooks/, in your AWS account. Successfully saved contents survive a stop and remain if the notebook is deleted. Save failures can leave recent edits unsaved.

The platform also stops a notebook on its own. The idle timeout, set at creation and editable afterwards, controls when the backing session becomes idle. When it elapses, the session enters its idle close delay and then stops the notebook.

A cell that is still running counts as activity, whether or not the notebook is open in a browser. A long-running cell keeps the notebook alive until it finishes, and the idle timeout then runs from that point, so you have the full timeout to come back for the result.

Stopping early still pays

A Running notebook holds compute until the idle timeout fires, so stopping it yourself when you step away reclaims compute sooner. Starting it again is quick on a warm cluster.

Use Spark in a notebook ​

A new notebook's starter cells create the Spark session:

python
from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()

The runtime sets SPARK_REMOTE to the backing session's Spark Connect address, so the call needs no URL. As in a job, SparkContext and RDDs are not available; see Check Your Spark Code.

SQL cells run on the same session when their engine is spark, as in the starter SQL cell.

In cluster mode, each Spark session has its own worker pool. Max nodes applies to each Spark session. SparkSession.builder.create() requests another pool. SparkSession.builder.getOrCreate() reuses the active or default session in the same Python process. It creates a session if neither exists. Reuse the same spark variable across cells when you want to use the same workers. See How Compute Runs and Scales for node allocation and reuse.

Save and download generated files ​

Cells can write files to the /notebook directory. Hosted notebooks save only the notebook source and Marimo settings, so generated files are lost when the notebook stops. Download them first, for example as a ZIP with mo.download:

python
import shutil as _shutil
from pathlib import Path as _Path

_outputs = _Path("/notebook/outputs")
_outputs.mkdir(parents=True, exist_ok=True)
(_outputs / "report.csv").write_text("id,total\n1,42\n")

_archive = _shutil.make_archive("/notebook/outputs", "zip", _outputs)
mo.download(data=_Path(_archive).read_bytes(), filename="outputs.zip")

The download loads the whole ZIP into memory, so very large outputs may not fit.

Logs ​

Logs on the notebook page opens two live streams: notebook, the Marimo pod that runs the editor and your cells, and engine, the Sail driver of the backing session, where engine-side failures such as out-of-memory kills appear. They are available from the moment the notebook starts, and no longer available once its resources are cleaned up after a stop.

Environment variables and secrets ​

The environment variables of the notebook's runtime profile and its own overrides are available inside cells through os.environ, alongside the Sail engine. Use a managed secret for any credential your code needs, such as a database password or an API token, and reference it from the runtime profile or the notebook. A plain value shows in the notebook's effective settings to everyone who can read the notebook.

Never paste a credential into a cell. Notebook contents are saved as plain text, so a pasted value is stored with the notebook and shared with everyone who can read it. The same applies to printed values: a secret written to cell output is saved with the notebook.

Values are resolved when the notebook starts. After changing a variable or replacing a secret, stop and start the notebook to pick up the new value.

A few variable names are set by the notebook runtime itself, such as the Spark Connect address and the Python import path. A variable with one of those names is not delivered; the notebook refuses to start and its status message names the variable. Rename it in the runtime profile or the notebook.

External data access ​

Spark reads and writes in a notebook go through Sail, so they can reach any external data target granted to the compute profile. The notebook's own Python process does not get the profile's AWS access. If you call S3 directly with boto3, pandas, or another Python client, give that client its own credentials through a managed secret reference instead of pasting them into a cell.

Import and download the notebook file ​

A notebook's cells live in one marimo file in your network's workspace bucket. The notebook's page shows it in the Notebook file row, with when it was last saved, and lets you replace it or download it without starting the notebook. Only the notebook's owner sees the row.

The file must be a marimo notebook: a .py file of up to 1 MiB that imports marimo and declares its app. Jupyter (.ipynb), Databricks, and marimo markdown notebooks are refused. The file's code runs on your cluster with the notebook's access to your data, so you confirm that you trust it before it is uploaded.

Import replaces the notebook's cells with a file, and the notebook starts from it next time. Stop the notebook first: while it runs, the editor saves over the file. Download the current cells first if you want to keep them.

Download saves the notebook's file. While the notebook runs, you get its last save, which can be a few seconds behind the editor.

A notebook has no file until it first runs or you import one.

Run a notebook as a job ​

A notebook job runs this notebook on a schedule or from an orchestrator. Each run copies the notebook's saved contents when it starts, so you can keep editing while it runs.

  1. Open the notebook and click Run as job.
  2. The job form opens with Notebook as the job type and this notebook selected. It starts on the first of the notebook's teams you belong to, with the notebook's workload profiles and overrides. Check them, add a schedule or parameters if you need them, then click Save.

From then on, the job keeps its own workload profiles and overrides. Later changes to the notebook's settings do not reach the job.

Run as job is available once the notebook has saved source: after it first runs, or after you import a file into it. Only the notebook's owner can run it as a job.

Change the compute profile ​

The compute profile is editable only while the notebook is stopped. To move a notebook to bigger compute (or a different cluster), stop it, change the compute profile, and start it again.

Settings of a notebook ​

A notebook start takes the workload profiles and the notebook's overrides as they are then, and takes a settings snapshot of the effective settings. The Sail engine, the notebook pod and any retry of either use that settings snapshot until the notebook stops. An edit of a workload profile while the notebook runs reaches it at its next start. View effective settings on the notebook's page shows what a start would use now, and where each value comes from.

Team access ​

The notebook's team controls access according to each member's team role:

  • Team Admin and Editor can edit, start, and stop the notebook.
  • Viewer can view its details.
  • Only the creating member can open the notebook editor.

Organization roles can also grant management access, but they do not override the creator check for opening the editor.

API reference ​

  • Notebooks: CreateNotebook, StartNotebook, StopNotebook, OpenNotebook, UpdateNotebook, DeleteNotebook, plus team sharing. The notebook file: CreateNotebookSourceUpload, ImportNotebookSource, GetNotebookSourceDownload, DescribeNotebookSource.
  • API Reference: the workload config (compute profile) a notebook references.

Can't find the answer here? Email us: support@lakesail.com