Python SDK for the Nanny execution boundary — @tool, @rule, @agent decorators
Project description
nanny-sdk
Python SDK for Nanny — an execution boundary for autonomous AI agents.
@tool, @rule, and @agent decorators that enforce step limits, cost budgets, tool allowlists, and custom rules per function call. Works with LangChain, CrewAI, or any Python agent framework.
pip install nanny-sdk
Full docs: docs.nanny.run
How it works
Nanny runs as a parent process via nanny run. The SDK decorators communicate with it at each tool call to check limits before the function body executes. Outside nanny run, every decorator is a no-op — zero overhead in development and CI.
# Governed — enforcement active
nanny run
# Passthrough — decorators silent, agent runs normally
python agent.py
uv run agent.py
@tool — declare a governed tool
from nanny_sdk import tool
@tool(cost=10)
def fetch_page(url: str) -> str:
import httpx
return httpx.get(url).text
Before fetch_page runs, Nanny checks the allowlist, per-tool call limits, and charges 10 cost units against the budget. If any check fails, a NannyStop exception is raised and the function body never executes.
Async functions work identically:
@tool(cost=10)
async def fetch_page(url: str) -> str:
async with httpx.AsyncClient() as client:
r = await client.get(url)
return r.text
@rule — enforce a custom policy
from nanny_sdk import rule
@rule("no_sensitive_files")
def block_sensitive(ctx) -> bool:
path = ctx.last_tool_args.get("path", "")
return ".env" not in path and "secret" not in path
Rules run before every @tool call. Return False to stop execution with RuleDenied. The ctx object exposes requested_tool, last_tool_args, and counters.
@agent — activate named limits for a scope
In a multi-agent system, each agent has a different role and a different risk profile. @agent activates the right named limit set when each role runs, then reverts automatically when it's done:
from nanny_sdk import agent
@agent("researcher")
def run_research_loop(query: str) -> str:
...
Activates [limits.researcher] from nanny.toml for the duration of the function. Limits revert on exit, including on exception. Each role runs under its own budget and tool allowlist — hitting the analysis ceiling does not affect the reporter, and the analysis agent cannot call the reporter's tools.
nanny.toml example
[runtime]
mode = "local"
[start]
cmd = "uv run agent.py"
[limits]
steps = 50
cost = 200
timeout = 120000
[limits.researcher]
steps = 30
cost = 100
[tools]
allowed = ["fetch_page", "search"]
Stop reasons
When a limit is exceeded, a NannyStop exception is raised with one of these reasons:
| Reason | Cause |
|---|---|
BudgetExhausted |
Cost ceiling reached |
MaxStepsReached |
Step limit reached |
TimeoutExpired |
Wall-clock limit reached |
ToolDenied |
Tool not in the allowlist |
RuleDenied |
A rule returned False |
AgentCompleted |
Clean exit |
AgentNotFound |
Named limit set in @agent does not exist in nanny.toml |
BridgeUnavailable |
Bridge was active but unreachable — fails closed, never continues ungoverned |
Requirements
- Python 3.11+
httpx(only runtime dependency)nannyCLI:- macOS:
brew tap nanny-run/nanny && brew install nannyd - Linux:
curl -fsSL https://install.nanny.run | sh - Windows:
irm https://install.nanny.run/windows | iex
- macOS:
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanny_sdk-0.1.6.tar.gz.
File metadata
- Download URL: nanny_sdk-0.1.6.tar.gz
- Upload date:
- Size: 38.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e10d6540aa9985ba63a8cf3b13a745ebc3f15193acd39c50346c6f69e6132729
|
|
| MD5 |
a806cee94320756716707255ce9716cb
|
|
| BLAKE2b-256 |
2ec05c49fc0f633116b9d25860c9baee727d2362471c88d50edd2bda2d1f1411
|
Provenance
The following attestation bundles were made for nanny_sdk-0.1.6.tar.gz:
Publisher:
release.yml on nanny-run/nanny
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nanny_sdk-0.1.6.tar.gz -
Subject digest:
e10d6540aa9985ba63a8cf3b13a745ebc3f15193acd39c50346c6f69e6132729 - Sigstore transparency entry: 1340805463
- Sigstore integration time:
-
Permalink:
nanny-run/nanny@8fe741569cf003fff03b69eadacfabbc3f919c2c -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/nanny-run
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8fe741569cf003fff03b69eadacfabbc3f919c2c -
Trigger Event:
push
-
Statement type:
File details
Details for the file nanny_sdk-0.1.6-py3-none-any.whl.
File metadata
- Download URL: nanny_sdk-0.1.6-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03d5cbfe104b2927d3e0f207126a7fd7c5c59caaa26133b03d2a01b57c179fe2
|
|
| MD5 |
033d6baf03aeb54a26de14e88dad521d
|
|
| BLAKE2b-256 |
147683344c1a30bd0547e10b00d53786a894eb0e76b6285595c59f234d7107b0
|
Provenance
The following attestation bundles were made for nanny_sdk-0.1.6-py3-none-any.whl:
Publisher:
release.yml on nanny-run/nanny
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nanny_sdk-0.1.6-py3-none-any.whl -
Subject digest:
03d5cbfe104b2927d3e0f207126a7fd7c5c59caaa26133b03d2a01b57c179fe2 - Sigstore transparency entry: 1340805466
- Sigstore integration time:
-
Permalink:
nanny-run/nanny@8fe741569cf003fff03b69eadacfabbc3f919c2c -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/nanny-run
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8fe741569cf003fff03b69eadacfabbc3f919c2c -
Trigger Event:
push
-
Statement type: