Skip to main content
Glama

execute_code

Destructive

Run code directly in Jupyter kernels or sandboxes for quick tests, debugging, magic commands, and shell commands without modifying notebooks.

Instructions

Execute code directly in a kernel (not saved to notebook).

If `use_sandbox` selected an active sandbox, this tool executes on that
sandbox instead of a Jupyter kernel. This allows agents to switch between
kernel-backed and sandbox-backed execution using the same execute_code API.

Targets the current activated notebook's kernel by default. Pass kernel_id
to execute in a specific kernel directly — including raw kernels with no
notebook attached.

Recommended to use in following cases:
1. Execute Jupyter magic commands(e.g., `%timeit`, `%pip install xxx`)
2. Performance profiling and debugging.
3. View intermediate variable values(e.g., `print(xxx)`, `df.head()`)
4. Temporary calculations and quick tests(e.g., `np.mean(df['xxx'])`)
5. Execute Shell commands in Jupyter server(e.g., `!git xxx`)

Under no circumstances should you use this tool to:
1. Import new modules or perform variable assignments that affect subsequent Notebook execution
2. Execute dangerous code that may harm the Jupyter server or the user's data without permission

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesCode to execute (supports magic commands with %, shell commands with !)
timeoutNoMaximum seconds to wait for execution (0 = use config default)
kernel_idNoTarget an existing kernel by ID (e.g. a raw kernel with no notebook). If omitted, uses the current notebook's kernel.
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations include destructiveHint=true, which is reinforced by the warning about dangerous code. The description adds transparency about sandbox switching and non-persistence ('not saved to notebook'). However, it does not fully disclose all side effects (e.g., variable assignment persistence despite warning), but the warning covers key risks.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear opening, recommended uses, and forbidden uses. While somewhat lengthy, every section adds value. Minor redundancy in the bullet points, but overall efficient for the information density.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description adequately covers execution environment, constraints, and examples. It explains the dual execution modes and provides useful guidance. It does not describe return values, but the schema covers parameters well and the sibling tools list provides context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with good parameter descriptions. The description adds context beyond the schema by explaining kernel_id's use for raw kernels and the sandbox alternative. It helps agents understand parameter meaning but does not add extensive new details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The name 'execute_code' and initial sentence 'Execute code directly in a kernel (not saved to notebook)' clearly convey a specific verb and resource. This distinguishes it from sibling tools like 'execute_cell' (which executes notebook cells) and 'insert_execute_code_cell' (which inserts a new cell and executes).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit when-to-use scenarios (6 bullet points for recommended uses) and when-not-to-use (2 forbidden actions). It explains the sandbox vs kernel choice and the role of kernel_id, offering clear context for selecting this tool over alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/datalayer/jupyter-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server