:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(notebooks): tell the agent what a notebook sandbox costs (#91025)
Sinan Kucukkoseler76b38959a780
diff --git a/products/notebooks/mcp/tools.yaml b/products/notebooks/mcp/tools.yamlindex b0e207b202ec..699e7135bfe4 100644--- a/products/notebooks/mcp/tools.yaml+++ b/products/notebooks/mcp/tools.yaml@@ -30,6 +30,23 @@ tools:notebooks-collab-stream-retrieve:operation: notebooks_collab_stream_retrieveenabled: false+ notebooks-compute-options:+ operation: notebooks_kernel_compute_options_retrieve+ enabled: true+ scopes:+ - notebook:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: Get notebook compute options+ description: >+ The rates a notebook's sandbox is priced at, the sized presets a user can pick from, and the cpu_cores and+ memory_gb values notebooks-configure-compute accepts. The rates are the same for every notebook in the+ region, so fetch this once per session rather than per notebook. Use it to quote a price before you start or+ resize a sandbox: a shape costs cpu_cores x cpu_rate_per_core_hour + memory_gb x memory_rate_per_gb_hour per+ hour, rounded to four decimal places, and each preset carries that total as hourly_price.+ feature_flag: revamped-py-notebooksnotebooks-configure-compute:operation: notebooks_kernel_config_createenabled: true@@ -42,9 +59,15 @@ tools:title: Configure notebook computedescription: >Set the notebook's sandbox kernel resources (cpu_cores, memory_gb from supported options;- idle_timeout_seconds). Config applies when a sandbox is provisioned — the response's restart_required is- true when a kernel is already active, meaning it keeps its current resources until restarted (restarting- loses materialized dataframes, so prefer configuring before the first Python cell runs).+ idle_timeout_seconds). Changing cpu_cores or memory_gb restarts a running kernel so the new size takes+ effect, and the response's restarted says whether that happened. A restart discards every materialized+ dataframe, so cells that referenced one must run again — prefer sizing the sandbox before the first Python+ cell runs, and tell the user what a mid-analysis resize will cost them. Changing only idle_timeout_seconds+ never restarts; restart_required then reports that a live kernel will not pick it up until it restarts on+ its own. The user pays for the sandbox for as long as it runs, so tell them the response's hourly_price in+ dollars whenever you set or change the size. That price always describes the sandbox actually serving the+ notebook, so if a restart failed it is the old one still running, not the size you just set.+ notebooks-compute-options lists the presets and the values this tool accepts.feature_flag: revamped-py-notebooksnotebooks-create:operation: notebooks_create@@ -168,7 +191,9 @@ tools:The dataframes and DuckDB tables the notebook's kernel currently holds — what a SQL or Python cell canreference by name — with column names/types and row counts, plus the kernel's live status and computeconfig. Frames are empty unless the kernel is running (SQL-only notebooks never start one; frames appear- after Python/DuckDB cells run). To probe deeper than the schema, run a SELECT in a cell.+ after Python/DuckDB cells run). To probe deeper than the schema, run a SELECT in a cell. Only a modal+ backend is charged: hourly_price is calculated for a local docker kernel too, so quote it to the user only+ when backend is modal.feature_flag: revamped-py-notebooksresponse:include:@@ -177,6 +202,9 @@ tools:- cpu_cores- memory_gb- idle_timeout_seconds+ - backend+ - hourly_price+ - preset_keyinformational_wrapper:tag: notebook-framespurpose:@@ -242,7 +270,8 @@ tools:node id from the notebook content. A cell that reads other cells' dataframes must list them in refs, andthose cells must have completed a run first — refs resolve to each upstream cell's last completed run, sorun cells in dependency order. The first Python cell run can take noticeably longer while the notebook's- sandbox kernel starts.+ sandbox kernel starts. That run also provisions the sandbox when none is up, and the user pays for it while+ it runs, so tell them its hourly_price (from notebooks-list-frames) the first time a run starts one.feature_flag: revamped-py-notebooksnotebooks-run-cell-interrupt:operation: notebooks_sql_v2_runs_interrupt_creatediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 6cdcb1e203a8..5fec96a9d6f3 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -7949,8 +7949,23 @@"feature_flag": "metrics","system_prompt_hint": "Discover which server/infrastructure metrics exist before querying them"},+ "notebooks-compute-options": {+ "description": "The rates a notebook's sandbox is priced at, the sized presets a user can pick from, and the cpu_cores and memory_gb values notebooks-configure-compute accepts. The rates are the same for every notebook in the region, so fetch this once per session rather than per notebook. Use it to quote a price before you start or resize a sandbox: a shape costs cpu_cores x cpu_rate_per_core_hour + memory_gb x memory_rate_per_gb_hour per hour, rounded to four decimal places, and each preset carries that total as hourly_price.",+ "category": "Notebooks",+ "feature": "notebooks",+ "summary": "Get notebook compute options",+ "title": "Get notebook compute options",+ "required_scopes": ["notebook:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "feature_flag": "revamped-py-notebooks"+ },"notebooks-configure-compute": {- "description": "Set the notebook's sandbox kernel resources (cpu_cores, memory_gb from supported options; idle_timeout_seconds). Config applies when a sandbox is provisioned — the response's restart_required is true when a kernel is already active, meaning it keeps its current resources until restarted (restarting loses materialized dataframes, so prefer configuring before the first Python cell runs).",+ "description": "Set the notebook's sandbox kernel resources (cpu_cores, memory_gb from supported options; idle_timeout_seconds). Changing cpu_cores or memory_gb restarts a running kernel so the new size takes effect, and the response's restarted says whether that happened. A restart discards every materialized dataframe, so cells that referenced one must run again — prefer sizing the sandbox before the first Python cell runs, and tell the user what a mid-analysis resize will cost them. Changing only idle_timeout_seconds never restarts; restart_required then reports that a live kernel will not pick it up until it restarts on its own. The user pays for the sandbox for as long as it runs, so tell them the response's hourly_price in dollars whenever you set or change the size. That price always describes the sandbox actually serving the notebook, so if a restart failed it is the old one still running, not the size you just set. notebooks-compute-options lists the presets and the values this tool accepts.","category": "Notebooks","feature": "notebooks","summary": "Configure notebook compute",@@ -8024,7 +8039,7 @@}},"notebooks-list-frames": {- "description": "The dataframes and DuckDB tables the notebook's kernel currently holds — what a SQL or Python cell can reference by name — with column names/types and row counts, plus the kernel's live status and compute config. Frames are empty unless the kernel is running (SQL-only notebooks never start one; frames appear after Python/DuckDB cells run). To probe deeper than the schema, run a SELECT in a cell.",+ "description": "The dataframes and DuckDB tables the notebook's kernel currently holds — what a SQL or Python cell can reference by name — with column names/types and row counts, plus the kernel's live status and compute config. Frames are empty unless the kernel is running (SQL-only notebooks never start one; frames appear after Python/DuckDB cells run). To probe deeper than the schema, run a SELECT in a cell. Only a modal backend is charged: hourly_price is calculated for a local docker kernel too, so quote it to the user only when backend is modal.","category": "Notebooks","feature": "notebooks","summary": "List notebook dataframes",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 540658073c2b..46ca0a676c55 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -8360,7 +8360,7 @@}},"notebooks-add-cell": {- "description": "Add a cell to a markdown notebook. SQL and Python cells run immediately: the call waits up to ~45s and returns the result — columns, a capped row preview, stdout/stderr (a Python cell's logs and tracebacks), and error — so you can look at the output and decide the next step (fix, or proceed). If the status comes back 'running', poll notebooks-run-cell-result with the run_id. A cell that reads other cells' dataframes references them by dataframe_name; those cells must have completed a run first, so add cells in dependency order. SQL cells are always HogQL: queries against PostHog or data warehouse tables run on ClickHouse, and a SQL cell that references a Python-created dataframe runs on the notebook's local engine automatically — any local dataframe is queryable by name, same syntax. The first Python cell can take longer while the notebook's sandbox kernel starts. Run analysis Python here rather than in a runtime the user can't see — dataframe work, statistics, clustering, forecasting, plotting — so the code and its output stay visible and re-runnable beside the result; the sandbox has pandas, numpy, scipy, scikit-learn, and matplotlib. component cells add other node types: Query, Image, Embed, Latex, FeatureFlag, Survey, Experiment, Person, Cohort, Recording, RecordingPlaylist. Pass a short title on every cell you add, describing what that cell shows — it renders in the cell header and is what a reader skims instead of the code. A notebook holds at most 50 cells; past that the call fails, so start a new notebook rather than retrying.",+ "description": "Add a cell to a markdown notebook. SQL and Python cells run immediately: the call waits up to ~45s and returns the result — columns, a capped row preview, stdout/stderr (a Python cell's logs and tracebacks), and error — so you can look at the output and decide the next step (fix, or proceed). If the status comes back 'running', poll notebooks-run-cell-result with the run_id. A cell that reads other cells' dataframes references them by dataframe_name; those cells must have completed a run first, so add cells in dependency order. SQL cells are always HogQL: queries against PostHog or data warehouse tables run on ClickHouse, and a SQL cell that references a Python-created dataframe runs on the notebook's local engine automatically — any local dataframe is queryable by name, same syntax. The first Python cell can take longer while the notebook's sandbox kernel starts. Run analysis Python here rather than in a runtime the user can't see — dataframe work, statistics, clustering, forecasting, plotting — so the code and its output stay visible and re-runnable beside the result; the sandbox has pandas, numpy, scipy, scikit-learn, and matplotlib. component cells add other node types: Query, Image, Embed, Latex, FeatureFlag, Survey, Experiment, Person, Cohort, Recording, RecordingPlaylist. Pass a short title on every cell you add, describing what that cell shows — it renders in the cell header and is what a reader skims instead of the code. A notebook holds at most 50 cells; past that the call fails, so start a new notebook rather than retrying. A Python cell provisions the notebook's sandbox when none is running, and the user pays for it while it runs, so tell them its hourly_price the first time a run starts one. notebooks-list-frames reports that rate, and notebooks-compute-options lists the presets.","category": "Notebooks","feature": "notebooks","summary": "Add a cell to a notebook; SQL/Python cells run immediately.",@@ -8374,8 +8374,23 @@"readOnlyHint": false}},+ "notebooks-compute-options": {+ "description": "The rates a notebook's sandbox is priced at, the sized presets a user can pick from, and the cpu_cores and memory_gb values notebooks-configure-compute accepts. The rates are the same for every notebook in the region, so fetch this once per session rather than per notebook. Use it to quote a price before you start or resize a sandbox: a shape costs cpu_cores x cpu_rate_per_core_hour + memory_gb x memory_rate_per_gb_hour per hour, rounded to four decimal places, and each preset carries that total as hourly_price.",+ "category": "Notebooks",+ "feature": "notebooks",+ "summary": "Get notebook compute options",+ "title": "Get notebook compute options",+ "required_scopes": ["notebook:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "feature_flag": "revamped-py-notebooks"+ },"notebooks-configure-compute": {- "description": "Set the notebook's sandbox kernel resources (cpu_cores, memory_gb from supported options; idle_timeout_seconds). Config applies when a sandbox is provisioned — the response's restart_required is true when a kernel is already active, meaning it keeps its current resources until restarted (restarting loses materialized dataframes, so prefer configuring before the first Python cell runs).",+ "description": "Set the notebook's sandbox kernel resources (cpu_cores, memory_gb from supported options; idle_timeout_seconds). Changing cpu_cores or memory_gb restarts a running kernel so the new size takes effect, and the response's restarted says whether that happened. A restart discards every materialized dataframe, so cells that referenced one must run again — prefer sizing the sandbox before the first Python cell runs, and tell the user what a mid-analysis resize will cost them. Changing only idle_timeout_seconds never restarts; restart_required then reports that a live kernel will not pick it up until it restarts on its own. The user pays for the sandbox for as long as it runs, so tell them the response's hourly_price in dollars whenever you set or change the size. That price always describes the sandbox actually serving the notebook, so if a restart failed it is the old one still running, not the size you just set. notebooks-compute-options lists the presets and the values this tool accepts.","category": "Notebooks","feature": "notebooks","summary": "Configure notebook compute",@@ -8479,7 +8494,7 @@}},"notebooks-list-frames": {- "description": "The dataframes and DuckDB tables the notebook's kernel currently holds — what a SQL or Python cell can reference by name — with column names/types and row counts, plus the kernel's live status and compute config. Frames are empty unless the kernel is running (SQL-only notebooks never start one; frames appear after Python/DuckDB cells run). To probe deeper than the schema, run a SELECT in a cell.",+ "description": "The dataframes and DuckDB tables the notebook's kernel currently holds — what a SQL or Python cell can reference by name — with column names/types and row counts, plus the kernel's live status and compute config. Frames are empty unless the kernel is running (SQL-only notebooks never start one; frames appear after Python/DuckDB cells run). To probe deeper than the schema, run a SELECT in a cell. Only a modal backend is charged: hourly_price is calculated for a local docker kernel too, so quote it to the user only when backend is modal.","category": "Notebooks","feature": "notebooks","summary": "List notebook dataframes",@@ -8556,7 +8571,7 @@"feature_flag": "revamped-py-notebooks"},"notebooks-update-cell": {- "description": "Update a SQL or Python cell's code and re-run it, or re-run it unchanged by omitting code (how you refresh a stale cell). Waits up to ~45s and returns the result like notebooks-add-cell, plus stale_dependents: the downstream cells whose inputs this run invalidated. Nothing re-runs automatically — inspect each dependent and re-run it with this tool (no code) or fix it first, walking the graph one hop at a time.",+ "description": "Update a SQL or Python cell's code and re-run it, or re-run it unchanged by omitting code (how you refresh a stale cell). Waits up to ~45s and returns the result like notebooks-add-cell, plus stale_dependents: the downstream cells whose inputs this run invalidated. Nothing re-runs automatically — inspect each dependent and re-run it with this tool (no code) or fix it first, walking the graph one hop at a time. Re-running a Python cell provisions the notebook's sandbox when none is running, and the user pays for it while it runs, so tell them its hourly_price the first time a run starts one.","category": "Notebooks","feature": "notebooks","summary": "Update a cell's code and re-run it.",diff --git a/services/mcp/schema/tool-definitions.json b/services/mcp/schema/tool-definitions.jsonindex 33747edd5a62..fcf218aecaf5 100644--- a/services/mcp/schema/tool-definitions.json+++ b/services/mcp/schema/tool-definitions.json@@ -302,7 +302,7 @@}},"notebooks-add-cell": {- "description": "Add a cell to a markdown notebook. SQL and Python cells run immediately: the call waits up to ~45s and returns the result — columns, a capped row preview, stdout/stderr (a Python cell's logs and tracebacks), and error — so you can look at the output and decide the next step (fix, or proceed). If the status comes back 'running', poll notebooks-run-cell-result with the run_id. A cell that reads other cells' dataframes references them by dataframe_name; those cells must have completed a run first, so add cells in dependency order. SQL cells are always HogQL: queries against PostHog or data warehouse tables run on ClickHouse, and a SQL cell that references a Python-created dataframe runs on the notebook's local engine automatically — any local dataframe is queryable by name, same syntax. The first Python cell can take longer while the notebook's sandbox kernel starts. Run analysis Python here rather than in a runtime the user can't see — dataframe work, statistics, clustering, forecasting, plotting — so the code and its output stay visible and re-runnable beside the result; the sandbox has pandas, numpy, scipy, scikit-learn, and matplotlib. component cells add other node types: Query, Image, Embed, Latex, FeatureFlag, Survey, Experiment, Person, Cohort, Recording, RecordingPlaylist. Pass a short title on every cell you add, describing what that cell shows — it renders in the cell header and is what a reader skims instead of the code. A notebook holds at most 50 cells; past that the call fails, so start a new notebook rather than retrying.",+ "description": "Add a cell to a markdown notebook. SQL and Python cells run immediately: the call waits up to ~45s and returns the result — columns, a capped row preview, stdout/stderr (a Python cell's logs and tracebacks), and error — so you can look at the output and decide the next step (fix, or proceed). If the status comes back 'running', poll notebooks-run-cell-result with the run_id. A cell that reads other cells' dataframes references them by dataframe_name; those cells must have completed a run first, so add cells in dependency order. SQL cells are always HogQL: queries against PostHog or data warehouse tables run on ClickHouse, and a SQL cell that references a Python-created dataframe runs on the notebook's local engine automatically — any local dataframe is queryable by name, same syntax. The first Python cell can take longer while the notebook's sandbox kernel starts. Run analysis Python here rather than in a runtime the user can't see — dataframe work, statistics, clustering, forecasting, plotting — so the code and its output stay visible and re-runnable beside the result; the sandbox has pandas, numpy, scipy, scikit-learn, and matplotlib. component cells add other node types: Query, Image, Embed, Latex, FeatureFlag, Survey, Experiment, Person, Cohort, Recording, RecordingPlaylist. Pass a short title on every cell you add, describing what that cell shows — it renders in the cell header and is what a reader skims instead of the code. A notebook holds at most 50 cells; past that the call fails, so start a new notebook rather than retrying. A Python cell provisions the notebook's sandbox when none is running, and the user pays for it while it runs, so tell them its hourly_price the first time a run starts one. notebooks-list-frames reports that rate, and notebooks-compute-options lists the presets.","category": "Notebooks","feature": "notebooks","summary": "Add a cell to a notebook; SQL/Python cells run immediately.",@@ -317,7 +317,7 @@}},"notebooks-update-cell": {- "description": "Update a SQL or Python cell's code and re-run it, or re-run it unchanged by omitting code (how you refresh a stale cell). Waits up to ~45s and returns the result like notebooks-add-cell, plus stale_dependents: the downstream cells whose inputs this run invalidated. Nothing re-runs automatically — inspect each dependent and re-run it with this tool (no code) or fix it first, walking the graph one hop at a time.",+ "description": "Update a SQL or Python cell's code and re-run it, or re-run it unchanged by omitting code (how you refresh a stale cell). Waits up to ~45s and returns the result like notebooks-add-cell, plus stale_dependents: the downstream cells whose inputs this run invalidated. Nothing re-runs automatically — inspect each dependent and re-run it with this tool (no code) or fix it first, walking the graph one hop at a time. Re-running a Python cell provisions the notebook's sandbox when none is running, and the user pays for it while it runs, so tell them its hourly_price the first time a run starts one.","category": "Notebooks","feature": "notebooks","summary": "Update a cell's code and re-run it.",diff --git a/services/mcp/src/generated/notebooks/api.ts b/services/mcp/src/generated/notebooks/api.tsindex e51e191ce735..006520fbefc3 100644--- a/services/mcp/src/generated/notebooks/api.ts+++ b/services/mcp/src/generated/notebooks/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 10 enabled ops+ * PostHog API - MCP 11 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -266,3 +266,14 @@ export const NotebooksSqlV2StateRetrieveParams = () => zod.object({),short_id: zod.string(),})++/**+ * Compute rates, presets, and the sizes the kernel config endpoint accepts. Static per region, so a client can fetch it once and price any shape a user picks.+ */+export const NotebooksKernelComputeOptionsRetrieveParams = () => zod.object({+ project_id: zod+ .string()+ .describe(+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."+ ),+})diff --git a/services/mcp/src/tools/generated/notebooks.ts b/services/mcp/src/tools/generated/notebooks.tsindex 38b0e9cf04bf..fc9768d0f77f 100644--- a/services/mcp/src/tools/generated/notebooks.ts+++ b/services/mcp/src/tools/generated/notebooks.ts@@ -13,6 +13,24 @@ import {} from '@/tools/tool-utils'import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'+const NotebooksComputeOptionsSchema = () => z.object({})++const notebooksComputeOptions = (): ToolBase<+ ReturnType<typeof NotebooksComputeOptionsSchema>,+ Schemas.NotebookComputeOptionsResponse+> => ({+ name: 'notebooks-compute-options',+ schema: NotebooksComputeOptionsSchema(),+ handler: async (context: Context, _params: z.infer<ReturnType<typeof NotebooksComputeOptionsSchema>>) => {+ const projectId = await context.stateManager.getProjectId()+ const result = await context.api.request<Schemas.NotebookComputeOptionsResponse>({+ method: 'GET',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/notebooks/kernel/compute_options/`,+ })+ return result+ },+})+const NotebooksConfigureComputeSchema = () => {const NotebooksKernelConfigCreateBody = orvalSchemas.NotebooksKernelConfigCreateBody()const NotebooksKernelConfigCreateParams = orvalSchemas.NotebooksKernelConfigCreateParams()@@ -181,6 +199,9 @@ const notebooksListFrames = (): ToolBase<'cpu_cores','memory_gb','idle_timeout_seconds',+ 'backend',+ 'hourly_price',+ 'preset_key',]) as typeof resultreturn withInformationalResponse(filtered,@@ -301,6 +322,7 @@ const notebooksRunCellResult = (): ToolBase<})export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {+ 'notebooks-compute-options': notebooksComputeOptions,'notebooks-configure-compute': notebooksConfigureCompute,'notebooks-create': notebooksCreate,'notebooks-destroy': notebooksDestroy,