From 75d6e2fc109d6886fb01d152e30af0bfb168cb95 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 27 Feb 2026 21:25:40 -0500 Subject: [PATCH] Document resource limits for MontySandboxProvider --- docs/servers/transforms/code-mode.mdx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/servers/transforms/code-mode.mdx b/docs/servers/transforms/code-mode.mdx index 2a6db4921..df4e094ba 100644 --- a/docs/servers/transforms/code-mode.mdx +++ b/docs/servers/transforms/code-mode.mdx @@ -138,6 +138,30 @@ mcp = FastMCP( ) ``` +### Resource Limits + +The default `MontySandboxProvider` can enforce execution limits on sandboxed code — timeouts, memory caps, recursion depth, and more. Without limits, LLM-generated scripts can run indefinitely. + +```python +from fastmcp.experimental.transforms import CodeMode, MontySandboxProvider + +mcp.add_transform(CodeMode( + sandbox_provider=MontySandboxProvider( + limits={"max_duration_secs": 10, "max_memory": 50_000_000}, + ), +)) +``` + +All keys are optional — omit any to leave that dimension uncapped: + +| Key | Type | Description | +|---|---|---| +| `max_duration_secs` | `float` | Maximum wall-clock execution time | +| `max_memory` | `int` | Memory ceiling in bytes | +| `max_allocations` | `int` | Cap on total object allocations | +| `max_recursion_depth` | `int` | Maximum recursion depth | +| `gc_interval` | `int` | Garbage collection frequency | + ### Custom Sandbox Providers The default `MontySandboxProvider` uses [pydantic-monty](https://github.com/pydantic/pydantic-monty) for sandboxed execution. You can replace it with any object implementing the `SandboxProvider` protocol: