Build zero-trust agents with 10xGraph
In shortCheck every tool call against the caller with ToolGuard, ask a human before risky tools, fence tool output, use mTLS on each link and see what stays your job.
- 13 min read
- 11 sections
- Updated
- v1.0.0
- Markdown
Zero trust for an agent means one thing in practice: the model never gets more power than the person it acts for. Every tool call is checked against the caller’s identity at the moment it runs, risky actions wait for a human, and text that comes back from tools is treated as data, not as instructions.
10xGraph gives you these controls in the framework; the policy (which tools, which permissions, who approves) is yours.
The model: check every call
A tool call passes these steps before the tool runs:
flowchart LR
M[Model asks for a tool] --> A{On the allow list?}
A -- no --> D[Denied by policy]
A -- yes --> P{Caller has the permission?}
P -- no --> D
P -- yes --> C{Argument check passes?}
C -- no --> D
C -- yes --> H{Needs approval?}
H -- yes --> I[Pause for a human] --> R{Approved?}
R -- no --> D
R -- yes --> T[Tool runs]
H -- no --> T
The caller is the Identity in config["user"]. The API server builds it from the verified token. In your own code you pass it yourself, as an Identity or a dict that validates into one. Identity.permissions holds resource:action strings. * allows everything and resource:* allows every action of a resource, so tools:* allows every tool. permissions=None means unrestricted, which is what a direct SDK call or a server with auth off gets.
By default a missing identity or permissions=None skips the permission check, as Identity defines it. Set strict=True to deny those calls instead. For deny by default, combine an allow list (anything not on it is denied) with strict=True.
ToolGuard
ToolGuard (tenxgraph.core.graph) is a ready-made policy that runs as a before_invoke callback for local and MCP tools. It takes five arguments, all optional:
| Argument | What it does |
|---|---|
allow |
Set of tool name patterns (fnmatch, case-sensitive, so "search_*" works). When set, a tool that matches none is denied. None (default) means no allow list. |
permissions |
{pattern: permission or set of permissions}. A call needs every permission of every matching pattern, checked with Identity.can. |
check |
check(tool_name, args, identity), sync or async. Return None to allow, or a string (the reason) to deny. Raising ToolDenied denies too. Any other exception denies and is logged (fail closed). args are the model’s raw arguments. |
approval |
Set of tool name patterns that need a human yes before they run. |
strict |
False (default). With True, a tool that has a permission rule is denied when there is no identity or identity.permissions is None. Tools without a rule are not affected. |
The checks run in that order: allow list, permissions, argument check, approval. A human is never asked about a call that a rule already denied. Tools that match no rule run as before.
Register the guard on the CallbackManager you pass to compile(). Each compiled graph uses only the manager it was compiled with, so a guard applies to that graph alone.
import asyncio
from tenxgraph.core.authz import Identity
from tenxgraph.core.graph import ToolGuard
from tenxgraph.core.state import Message
from tenxgraph.prebuilt.agent import ReactAgent
from tenxgraph.storage.checkpointer import InMemoryCheckpointer
from tenxgraph.utils import CallbackManager, ResponseGranularity
def get_order(order_id: str) -> str:
"""Look up an order."""
return f"Order {order_id}: delivered, 20 dollars."
def refund(order_id: str, amount: float) -> str:
"""Refund an order. Use it whenever the user asks for a refund."""
return f"Refund of {amount} issued for order {order_id}."
def delete_customer(customer_id: str) -> str:
"""Delete a customer record."""
return f"Customer {customer_id} deleted."
def refund_limit(name: str, args: dict, identity: Identity | None) -> str | None:
if name == "refund" and args.get("amount", 0) > 500:
return "Refunds above 500 need a manager."
return None
manager = CallbackManager()
ToolGuard(
allow={"get_order", "refund"}, # delete_customer is denied for everyone
permissions={"refund": "tools:refund"},
check=refund_limit,
strict=True,
).register(manager)
agent = ReactAgent(
model="gpt-5-mini",
system_prompt=[{"role": "system", "content": "You are a support assistant. Use the tools to act."}],
tools=[get_order, refund, delete_customer],
)
app = agent.compile(checkpointer=InMemoryCheckpointer(), callback_manager=manager)
async def main() -> None:
config = {
"thread_id": "support-1",
"user": Identity(user_id="u-42", permissions=frozenset({"graph:invoke"})),
}
async with app:
result = await app.ainvoke(
{"messages": [Message.text_message("Refund 20 dollars for order A-1001.")]},
config,
response_granularity=ResponseGranularity.FULL,
)
for message in result["state"].context:
if message.role == "tool":
print(message.text())
asyncio.run(main())The caller has no tools:refund, so the refund never runs and the model gets:
Denied by policy: refund. Missing permission: tools:refund.Give the caller permissions=frozenset({"tools:refund"}) (or tools:*) and the same call runs.
The guard matches the tool name the model sees. For MCP tools that is the name with any mcp_prefix in front.
Human approval
Tools in approval pause the run with interrupt() before they run. The pause has reason "tool_approval" and is keyed to the tool call, so parallel calls are approved one by one. Its value is {"tool_name", "args", "tool_call_id", "action"}. Approval needs a checkpointer, because the paused run is saved and resumed.
from tenxgraph.utils import pending_interrupt
manager = CallbackManager()
ToolGuard(approval={"refund"}).register(manager)
app = agent.compile(checkpointer=InMemoryCheckpointer(), callback_manager=manager)
config = {"thread_id": "approval-1", "user": Identity(user_id="u-42", permissions=frozenset({"tools:refund"}))}
async with app:
first = await app.ainvoke(
{"messages": [Message.text_message("Refund 20 dollars for order A-1001.")]},
config,
response_granularity=ResponseGranularity.FULL,
)
request = pending_interrupt(first["state"])
if request is not None and request.reason == "tool_approval":
print(request.message) # Approve: Run tool 'refund'?
print(request.value) # {"tool_name": "refund", "args": {...}, "tool_call_id": "...", "action": "Run tool 'refund'"}
final = await app.ainvoke(
{"resume": True, "resume_interrupt_id": request.id},
config,
response_granularity=ResponseGranularity.FULL,
)Resume values:
Trueor{"approved": True}runs the tool once. Its result goes to the tool ledger, so a later replay of the node does not run it again.None(a cancel),False,{"approved": False}or anything else denies it. The model getsDenied by policy: refund. A human reviewer did not approve this call.
resume_interrupt_id is optional. With it, a resume that names a different interrupt raises InterruptMismatchError, so a stale or retried request cannot answer the next prompt. From the TypeScript client, approveInterrupt(interrupt) sends true and rejectInterrupt(interrupt) sends null.
A tool that needs approval but runs outside a graph (a direct ToolNode.invoke) is denied: nobody can answer the pause. See Pause for human input for interrupts in general.
What the model, the stream and the trace see
A denied call never runs. The ToolNode:
- answers the model with a failed tool result,
"Denied by policy: <tool>. <reason>", plus an error block with codeTOOL_DENIED. The tool message hastool_deniedset in its metadata. - skips
on_errorrecovery, so a recovery callback can never turn a block into a success. - logs a warning with the tool name, user id and reason. Argument values are never logged.
- publishes the tool event with status
denied. With the OTEL publisher the tool span gets the attributetenxgraph.tool.deniedset toTrue.
The run itself goes on, so the model can tell the user what happened. In a streamed run the denial arrives as an error chunk:
from tenxgraph.core.state import StreamEvent
async for chunk in app.astream(input_data, config):
if chunk.event == StreamEvent.ERROR and chunk.data.get("status") == "tool_denied":
print(chunk.data["tool_name"], chunk.data["error"])Other tool failures keep status tool_failed.
What the guard does not cover
- Client tools (
remote_toolsandattach_remote_tools) run in the frontend, not in the ToolNode, so nobefore_invokecallback sees them. - Skill tools (
activate_skill) report asInvocationType.SKILLand are not guarded. - Provider server tools (for example Anthropic’s
code_execution) run on the provider’s side and never reach the ToolNode.
Hiding a tool is not enforcement. mcp_include, mcp_exclude and tool tags shape the list the model sees, but a model can still name a hidden tool. The guard is what blocks the call.
Raise ToolDenied from your own callback
When your rule does not fit ToolGuard, write a before_invoke callback and raise ToolDenied (tenxgraph.core.exceptions). It gets the same handling as a guard denial. You can also raise it inside a tool.
from tenxgraph.core.exceptions import ToolDenied
from tenxgraph.utils import CallbackManager, InvocationType
async def no_deletes(context, input_data):
if context.function_name.startswith("delete_"):
raise ToolDenied("Deleting is turned off for this assistant.")
return input_data
manager = CallbackManager()
manager.register_before_invoke(InvocationType.TOOL, no_deletes)
manager.register_before_invoke(InvocationType.MCP, no_deletes)
app = graph.compile(callback_manager=manager)ToolDenied(reason, tool_name=None): the ToolNode fills in tool_name when you leave it out. The reason goes to the model, the logs and the events, so keep it short and free of secrets and argument values. The callback context holds tool_call_id, args and config in context.metadata.
Tool result fencing
A web page, a file or an MCP server can return text that tries to steer the model (“ignore your instructions and…”). The text of every tool result reaches the model inside a fence, <tool_output_xxxxxxxx>, and one system prompt line tells the model the content is data returned by a tool, not instructions. This is on by default for local, MCP and client tools.
- Only the outgoing model request is wrapped. Saved messages, API responses, events and traces keep the plain output.
- Text inside a result that looks like the fence’s tags (
<tool_outputor</tool_output, any case) is escaped, so a result cannot close the fence or fake an opening one. - Results the framework writes itself are not fenced: handoff answers, skill tools and
ToolDeniedresults. - It is cache-safe. The suffix is derived from the message id and the tool call id, so the same saved result gets the same fence on every turn. The system prompt line is added whenever tools exist, from the first turn on.
Fencing lowers the chance that the model obeys injected text. It does not make that impossible, which is why the guard and approvals sit behind it.
To turn it off, set fence_results=False on the ToolNode the agent uses:
from tenxgraph.core.graph import Agent, ToolNode
tool_node = ToolNode([get_order, refund], fence_results=False)
agent = Agent(model="gpt-5-mini", tool_node=tool_node)Turn it off only when every result comes from code you trust and the fence gets in the way, for example a tool whose exact output a test compares against a recorded model request.
On the API server
Tool permissions live in the same role table as route permissions. The tools resource takes any tool name as its action:
tools:refund,tools:mcp.search-v2: one tool. A name is 1 to 128 ofA-Z a-z 0-9 _ - .. Any other character refuses to boot in a role and is ignored in a token claim.tools:*: every tool.*includestools:*.
{
"agent": "graph.react:app",
"auth": {
"method": "jwt",
"roles": {
"member": {"permissions": ["graph:*", "threads:*", "tools:get_order"], "reach": "own"},
"support": {"inherits": ["member"], "permissions": ["tools:refund"], "reach": "own"},
"super_admin": {"permissions": ["*"], "reach": "all"}
},
"default_role": "member"
}
}The server puts the caller’s Identity in config["user"] for every run, and ToolGuard reads it from there. Your graph module does not change:
# graph/react.py
manager = CallbackManager()
ToolGuard(
permissions={"get_order": "tools:get_order", "refund": "tools:refund"},
approval={"refund"},
strict=True,
).register(manager)
app = agent.compile(checkpointer=checkpointer, callback_manager=manager)Things to know:
- The default permission set (auth on, no roles and no permissions claim) has no tool permissions. A tool behind a
ToolGuardpermission rule is denied until a role or a permissions claim grants it. - Token
scopeandscopesclaims narrow tools too. A token with scopetools:refundnarrows atools:*grant to that one tool. - Tool permissions never grant a route, and a route cannot require one.
- With auth off there is no identity in
config["user"]. Withstrict=Falsethe guard then skips permission checks; withstrict=Trueit denies tools that have a permission rule.
See Authentication and roles for the role table and Permissions in tools for Identity and can().
Transport
TLS and mTLS end at your proxy or mesh; for the links the app opens (Postgres, Redis, LLM, MCP) see Use mutual TLS.
PII is your job
10xGraph does not classify, filter or redact personal data. Which values count as personal data, and what to do with them, is your policy. The hook is an after_invoke callback: whatever it returns replaces the tool output, and the replacement is what is saved to state and sent to the model.
For a local tool the output is whatever the function returned (a string, a dict, a ToolResult or a Message). For an MCP tool it is always a Message. This recipe masks emails and card numbers in all of them:
import re
from tenxgraph.core.state import Message, ToolResult, ToolResultBlock
from tenxgraph.utils import CallbackManager, InvocationType
EMAIL = re.compile(r"[\w.+-]+@[\w-]+(?:\.[\w-]+)+")
CARD = re.compile(r"\b(?:\d[ -]?){13,16}\b")
def mask(value):
if isinstance(value, str):
return CARD.sub("[CARD]", EMAIL.sub("[EMAIL]", value))
if isinstance(value, list):
return [mask(item) for item in value]
if isinstance(value, dict):
return {key: mask(item) for key, item in value.items()}
return value
async def redact_pii(context, input_data, output):
if isinstance(output, Message) and isinstance(output.content, list):
blocks = [
block.model_copy(update={"output": mask(block.output)})
if isinstance(block, ToolResultBlock)
else block
for block in output.content
]
return output.model_copy(update={"content": blocks})
if isinstance(output, ToolResult):
return ToolResult(message=mask(output.message), state=output.state, is_error=output.is_error)
return mask(output)
manager = CallbackManager()
manager.register_after_invoke(InvocationType.TOOL, redact_pii)
manager.register_after_invoke(InvocationType.MCP, redact_pii)Two regular expressions are a start, not a PII policy. Swap mask for your own rules or a detection service. The callback only sees tool output. Values the user types, and the tool arguments the model writes, reach the model and the stored thread without it. See Validate tool, MCP and RAG output for the full callback contract.
Sandboxes: through MCP or provider tools
10xGraph has no sandbox runtime. Run code in your own sandbox (E2B, Modal, Daytona, Docker or your own) behind an MCP server, or use a provider’s code execution tool. The framework only connects to it.
A sandbox behind MCP is a normal MCP tool, so the guard, approvals, fencing, tool events and tracing all apply to the call:
tool_node = ToolNode(tools=[], client=sandbox_client, mcp_prefix="sandbox_")
manager = CallbackManager()
ToolGuard(
permissions={"sandbox_*": "tools:sandbox"},
approval={"sandbox_run_code"},
strict=True,
).register(manager)To run each user’s calls with their own credential, use mcp_auth (see Call services as the user).
Code in the sandbox that calls tools directly skips 10xGraph. Those calls do not pass through the ToolNode, so they get no identity check, no ToolGuard, no tool event, no log line and no trace span. Give the sandbox only the network and credentials it needs, and route tool access through your graph. A provider’s code execution tool runs on the provider’s side, so the same holds there: the guard never sees what that code does.
Zero-trust controls and where they live
The table maps the controls of a typical zero-trust guide for AI agents to 10xGraph features. It is a map, not a certification.
| Control | 10xGraph feature | Your job |
|---|---|---|
| Verify every caller with short-lived tokens | JWT auth requires exp. Revocation by jti or by user. Authentication and roles |
Run the issuer, choose token lifetimes |
| Least privilege per role | Roles with permissions and reach own, tenant or all. Override BaseAuth.authorize for attribute rules |
Decide what each role may do |
| Least agency per tool, checked at call time | ToolGuard(permissions=...) with tools:<name> in roles |
Map tools to permissions |
| Deny by default | ToolGuard(allow=..., strict=True). The API’s default set has no tool permissions |
Keep the allow list short |
| Hiding is not blocking | mcp_include, mcp_exclude and tool tags hide. ToolGuard blocks |
Use both |
| Human approval for high-risk actions | ToolGuard(approval=...), one pause per tool call, interrupt() for anything custom |
Build the review UI, pick the approvers |
| Argument checks | ToolGuard(check=...), fail closed |
Write the rules |
| Tool credentials bound to the caller | UserCredential and ToolNode(mcp_auth=...). Call services as the user |
Token exchange with your identity provider |
| Data isolation by user and tenant | Identity reach scoping, tenant columns in Postgres. Tenant isolation |
Choose the tenant claims |
| Indirect prompt injection | Tool result fencing (on by default), fenced memory and RAG text, opt-in PromptInjectionValidator, after_invoke checks. Prompt-injection validators |
Check output of tools that read untrusted content |
| Action logs and tracing | Audit log (metadata only), denial logs with user id, tenxgraph.tool.denied on OTEL spans, tool events with status denied |
Storage, retention, alerting, tamper evidence |
| Loop and cost limits | recursion_limit (default 25), rate limiting |
Set budgets per run and per user |
| SSRF on fetched URLs | MediaFetchPolicy checks external media URLs. Security model |
Network egress rules for your own tools |
| Encryption in transit, mTLS | Each client takes TLS settings (see Use mutual TLS) | Proxy or mesh, certificates, rotation |
| Container hardening | 10xgraph build image: non-root user; the generated Kubernetes manifest adds a read-only root filesystem. Deploy |
Image scanning, runtime policy |
| PII detection and redaction | The after_invoke hook |
All of it: rules, detection, retention |
| Sandboxed code execution | Connects to your sandbox through MCP or a provider tool | Run and isolate the sandbox |
| Memory poisoning (provenance and expiry) | Each memory records its origin, optional expires_at, opt-in trusted-only retrieval and adelete_expired(). Memory origin and expiry |
Turn on trusted-only retrieval and a TTL, schedule the cleanup, review what the model wrote |
For the SOC 2 and ISO 27001 view, see Control mapping. For what the framework leaves out, see What 10xGraph does not protect.
Related pages
- Security model: What the server enforces and what stays yours.
- Permissions in tools:
Identity,get_identityandcan()inside tools. - Use callbacks:
before_invoke,after_invokeandon_error. - Use MCP tools: Connect MCP servers to a ToolNode.
Frequently asked questions
- Does hiding a tool from the model stop it from being called?
- No. A model can still name a hidden tool, by mistake or because an injected text told it to. Hiding (mcp_include, tool tags) only shapes the tool list. ToolGuard is what blocks the call.
- What does the model see when a tool call is denied?
- A failed tool result with the text 'Denied by policy: <tool>. <reason>'. The tool does not run, on_error recovery is skipped, and the run continues so the model can tell the user.