mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 21:44:18 +02:00
Document resource limits for MontySandboxProvider
This commit is contained in:
parent
18d5902367
commit
75d6e2fc10
1 changed files with 24 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue