The Hexr Python SDK is the entry point for building identity-first AI agents. With a single decorator, your agent receives a cryptographic SPIFFE identity that gates every downstream operation — cloud credential exchange, secret access, LLM cost tracking, and inter-agent communication — so you write agent logic instead of infrastructure plumbing.
Installation
uv pip install "hexr-sdk[cli]" --extra-index-url https://pypi.hexr.cloud/simple/
The Hexr SDK is distributed via a private PyPI registry. You need access credentials. For Hexr Cloud users, hexr login configures this automatically.
Quick example
from hexr import hexr_agent, hexr_tool, hexr_llm
import openai
@hexr_agent(name="market-analyst", tenant="acme-corp", a2a=True)
def analyze_market(sector: str) -> dict:
# Authenticated S3 client — zero credential management
s3 = hexr_tool("aws_s3")
# LLM with automatic cost tracking and tracing
client = hexr_llm(openai.OpenAI())
# Secrets from SPIFFE-native vault — no API keys
import hexr.vault
api_key = hexr.vault.get("research/api-key")
# Code execution in Firecracker microVM
import hexr.sandbox
result = hexr.sandbox.exec("import pandas; print(pandas.__version__)")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": f"Analyze the {sector} market"}]
)
return {"analysis": response.choices[0].message.content}
What happens automatically when you run this agent:
- A SPIFFE identity is assigned to this process
- All cloud calls are authenticated via a 3-tier credential cache
- Every LLM call is traced with model, tokens, latency, and cost
- OpenTelemetry spans are emitted for every SDK operation
- An A2A agent card is served for inter-agent discovery
Module map
| Import | Purpose | Docs |
|---|
from hexr import hexr_agent | Agent decorator | Reference |
from hexr import hexr_tool | Cloud tool factory | Reference |
from hexr import hexr_llm | LLM observability proxy | Reference |
import hexr.vault | Secrets management | Reference |
import hexr.gateway | MCP tool gateway | Reference |
import hexr.sandbox | Code execution | Reference |
import hexr.browser | Browser automation | Reference |
import hexr.guard | LLM Guard scanning | Reference |
from hexr.a2a import A2AClient | Agent-to-agent communication | Reference |
How loading works
Only the core module (hexr_agent, hexr_tool, hexr_llm) loads at import time. All other modules are lazy-loaded — they only import when first accessed:
import hexr.vault # Module loads only now
import hexr.sandbox # Module loads only now
This keeps agent startup fast and avoids loading unnecessary dependencies.
Environment variables
Most environment variables are set automatically by hexr deploy. For self-hosted deployments, you can override the defaults to point at your own cluster services:
| Variable | Description |
|---|
HEXR_FRAMEWORK | Framework type — auto-detected by hexr build, set at deploy time |
HEXR_TENANT | Tenant identifier — defaults to the tenant param on @hexr_agent |
HEXR_AGENT_NAME | Agent name — defaults to the name param on @hexr_agent |
HEXR_SANDBOX_ENABLED | Set to true to enable sandbox features (auto-detected in most deployments) |
HEXR_LLM_GUARD_ENABLED | Set to true to enable LLM Guard scanning (auto-detected in most deployments) |
On Hexr Cloud, all service endpoints are configured automatically. On self-hosted deployments, endpoint URLs for Vault, Gateway, Sandbox, and the OTel Collector are injected by the Hexr Helm chart at deploy time — you don’t set these manually.
Exceptions
All SDK exceptions inherit from HexrError:
from hexr import HexrError, AuthenticationError, CredentialError
try:
s3 = hexr_tool("aws_s3")
except AuthenticationError:
# SPIFFE identity not available
pass
except CredentialError:
# Cloud credential exchange failed
pass
except HexrError:
# Any other SDK error
pass
| Exception | When raised |
|---|
HexrError | Base exception for all SDK errors |
AuthenticationError | SPIFFE auth fails (no SVID available) |
CredentialError | Cloud credential exchange fails |
ConfigurationError | Invalid SDK configuration |
BuildError | hexr build processing fails |
DeploymentError | hexr deploy fails |
FrameworkError | Agent framework detection fails |
ProcessContextError | Process context file creation fails |
GuardrailError | LLM Guard blocks the request (has .scanners dict) |