Python SDKExecution Protection

Tool Protection & Adapters

Protect native Python callables, LangChain tools, LangGraph state nodes, and Model Context Protocol (MCP) servers with deterministic policy enforcement.

Registering Native Tools

Register any standard Python callable with SecureAgent.register_tool(). SICTACK preserves original typing, return values, and docstrings:

register_tool.py
def fetch_weather(city: str) -> dict:
    return {"city": city, "temperature_c": 22, "condition": "Sunny"}

# Register the Python function with SecureAgent
agent.register_tool(
    name="fetch_weather",
    func=fetch_weather,
    description="Fetches real-time weather metrics for a specified city",
    parameters={
        "type": "object",
        "properties": {
            "city": {"type": "string", "description": "City name"}
        },
        "required": ["city"],
    },
)

Executing Protected Tools

Execute tools by passing a ToolCall instance into agent.execute(). Prior to executing the underlying callable, the agent verifies permissions, evaluates policies, and computes the action hash:

execute_tool.py
from sictack import ToolCall

# Construct the immutable ToolCall model
call = ToolCall(tool_name="fetch_weather", arguments={"city": "San Francisco"})

# Executes the callable if allowed; raises exception if denied or requiring approval
result = agent.execute(call)
print(result)
# -> {'city': 'San Francisco', 'temperature_c': 22, 'condition': 'Sunny'}

Resuming with Approvals

When a tool requires human confirmation, execute() raises an ApprovalRequiredError. Resume execution with execute_with_approval():

resume_approval.py
from sictack import ToolCall
from sictack.exceptions import ApprovalRequiredError

call = ToolCall(tool_name="restart_server", arguments={"server_id": "srv-99"})

try:
    agent.execute(call)
except ApprovalRequiredError as e:
    # 1. Capture the issued approval_id
    ticket_id = e.approval_id
    
    # 2. Operator authorizes the action via UI or script
    agent.approve(ticket_id)
    
    # 3. Resume execution using the single-use token
    result = agent.execute_with_approval(call, approval_id=ticket_id)
    print("Action executed:", result)
Parameter Tampering Protection

If an attacker attempts to alter the parameters inside call.arguments between the initial denial and calling execute_with_approval, the action hash will not match and SICTACK will reject the call with an ApprovalMismatchError.

LangChain Integration (SecureTool)

Wrap existing LangChain tools with SecureTool. The wrapped tool adheres to the LangChain BaseTool contract:

langchain_demo.py
from langchain_core.tools import tool
from sictack.integrations.langchain import SecureTool, secure_langchain_tool

@tool
def calculate_vat(subtotal: float, country_code: str) -> float:
    """Calculates tax rate based on jurisdiction."""
    return subtotal * 0.20

# Method 1: Class wrapper
protected_tool = SecureTool(tool=calculate_vat, agent=agent)

# Method 2: Convenience decorator / helper
secured_tool = secure_langchain_tool(calculate_vat, agent=agent)

# When LangChain invokes the tool, SICTACK intercepts it automatically
tax = protected_tool.invoke({"subtotal": 100.0, "country_code": "GB"})

LangGraph Integration (SecureGraphNode)

Guard state transitions and node executions in LangGraph graphs using SecureGraphNode:

langgraph_demo.py
from sictack.integrations.langgraph import SecureGraphNode

# Wrap a graph state node before registering it in your StateGraph
def process_refund_node(state: dict) -> dict:
    # Business logic for refunds
    return {"status": "refund_issued", "amount": state["amount"]}

secure_node = SecureGraphNode(
    name="process_refund",
    node_func=process_refund_node,
    agent=agent
)

# Use secure_node inside your langgraph.graph.StateGraph

MCP Integration (MCPSecurityProxy)

Intercept Model Context Protocol (MCP) tool invocations before they reach downstream MCP servers using MCPSecurityProxy:

mcp_demo.py
from sictack.integrations.mcp import MCPSecurityProxy

# Wrap an existing MCP client connection with deterministic policy enforcement
proxy = MCPSecurityProxy(agent=agent)

# All incoming call_tool requests are verified against agent policies
response = proxy.intercept_tool_call(
    tool_name="read_file",
    arguments={"path": "/etc/hosts"}
)