---
title: "Execute arbitrary code in a session kernel (debug)"
method: POST
path: "/sessions/{sessionId}/execute"
tags: ["Sessions"]
---

# Execute arbitrary code in a session kernel (debug)

`POST /sessions/{sessionId}/execute`

Runs arbitrary code inside the notebook's kernel within an interactive session and returns the raw outputs (without creating a snapshot). User-code exceptions are returned as error outputs inside the response body and still produce HTTP 200.

## Path parameters

- `sessionId` string, uuid, required — Session identifier.

## Request body

- object
  - `notebookId` string, required — Source notebook to execute against in the session. Use the session's source notebook ID (`session.notebookId`), not `sessionNotebookId`.
  - `code` string, required — Source code to execute in the session sandbox.
  - `timeoutMs` integer — Maximum execution time in milliseconds. Must be a positive integer no greater than 120000. Values outside this range are rejected with 400; the server does not clamp. Defaults to 10000 when omitted.

## Response `200`

Outputs produced by the synchronous execution.

- ExecuteSessionResponse
  - `outputs` JupyterOutput[], required — Raw Jupyter (nbformat) outputs produced by the synchronous execution. User-code exceptions are returned as `output_type: "error"` entries here, not as HTTP errors.
    - union — A single Jupyter (nbformat) output entry.
      - JupyterStreamOutput — Jupyter `stream` output (stdout/stderr).
        - `output_type` 'stream', required
        - `name` 'stdout' | 'stderr', required
        - `text` union, required — Either a single string or an array of strings (multi-line text per nbformat).
          - string
          - string[]
      - JupyterErrorOutput — Jupyter `error` output (user-code exception).
        - `output_type` 'error', required
        - `ename` string, required
        - `evalue` string, required
        - `traceback` string[], required
      - JupyterDisplayDataOutput — Jupyter `display_data` output (rich MIME bundle).
        - `output_type` 'display_data', required
        - `data` object, required
        - `metadata` object
      - JupyterExecuteResultOutput — Jupyter `execute_result` output (final expression value of a cell).
        - `output_type` 'execute_result', required
        - `execution_count` integer, nullable, required
        - `data` object, required
        - `metadata` object
      - JupyterUnknownOutput — Catch-all for outputs whose `output_type` is not one of the well-known nbformat variants.
        - `output_type` string, required

## Other responses

- `400` — Validation error
- `401` — Unauthorized
- `403` — Insufficient permissions
- `404` — Session or notebook not found
- `408` — Execution timed out
- `409` — Project is suspended, the notebook is busy with a tracked run, or the session kernel is unavailable
- `429` — Rate limit exceeded
- `500` — Internal server error

---

[API](https://skmtc.net/deepnote/apis/deepnote-public-api.md) · [All operations](https://skmtc.net/deepnote/apis/deepnote-public-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/deepnote/deepnote-public-api/revisions/726970fd2992/schema)
