What You Will Build
By the end of this tutorial, you will have a running OpenLeash instance with an owner account, a registered agent, a YAML authorization policy, and a verified proof token. The entire setup runs locally — no cloud services, no databases, no external dependencies beyond Node.js.
Here is the flow: install OpenLeash, run the interactive wizard to create an owner and agent, write a policy that controls spending, send an authorization request, and verify the proof token that comes back. Each step builds on the previous one.
Prerequisites
You need Node.js 20 or later and npm. That is it. OpenLeash is a single npm package with no native dependencies. Check your version:
Step 1: Install and Initialize
Install OpenLeash globally or use npx to run it directly. The wizard
command walks you through initial setup: it creates a data directory, generates signing keys,
and sets up your first owner account.
The wizard creates a ./data directory containing your owner file, signing keys,
and a state index. All state is file-based — you can inspect, version control, or back up
the data directory at any time.
Step 2: Start the Server
Start the OpenLeash sidecar. It runs as a local HTTP server on port 8787 by default and includes a web GUI for managing agents, policies, and approval requests.
Open http://127.0.0.1:8787/gui in your browser to access the owner portal.
Log in with the passphrase you set during the wizard. From here you can create agent invites,
manage policies, and review approval requests.
Step 3: Register an Agent
Agents register by accepting an invite and providing an Ed25519 public key. The invite flow ensures only agents you authorize can connect. You can create an invite through the GUI or the API. Here we will use the TypeScript SDK from the agent's perspective:
The agent is now registered and bound to the owner. It can send authorization requests, but all requests will be denied until you create a policy that allows specific actions.
Step 4: Write a Policy
Policies define what actions an agent can perform and under what conditions. They are YAML files
stored in ./data/policies/. Here is a policy that allows the agent to make purchases
under $100, requires human approval for $100-$500, and denies anything above $500:
You can also create and manage policies through the CLI (npx openleash policy upsert)
or the owner API. Policies take effect immediately — no server restart required.
Step 5: Authorize an Action
Now the agent can request authorization before performing actions. The SDK handles Ed25519 request signing automatically. Here is an authorization request for a $45 purchase:
The request is evaluated against the spending policy. Since $45 is under the $100 threshold,
the decision is ALLOW and OpenLeash returns a signed PASETO proof token. The agent
can now proceed with the purchase and present the proof token to the vendor.
If the agent had requested a $250 purchase, the decision would be REQUIRE_APPROVAL,
and the agent would need to wait for the owner to approve through the GUI or API. A $600 purchase
would be denied outright.
Step 6: Verify the Proof Token
The counterparty (the service receiving the agent's request) verifies the proof token to confirm the action was authorized. Verification can be done offline using the owner's public key or online by calling the OpenLeash verification endpoint:
Offline verification uses only the public key and the token itself — no network call to OpenLeash. This means proof tokens work even when the authorization server is offline, across different networks, and with zero additional latency.
For online verification (useful when you do not have the public key cached), use the
POST /v1/verify-proof endpoint or verifyProofOnline() in the SDK.
What Happens in the Audit Log
Every authorization decision is recorded in the append-only audit log at ./data/audit.log.jsonl.
Each line is a JSON object with the full request, decision, policy matches, and timestamp.
The log is useful for debugging policy behavior, compliance reporting, and understanding
how your agent is operating over time.
Next Steps
You now have a working authorization setup. From here you can:
- Write more policies for different action types (email, file access, API calls)
- Set up approval workflows for high-value actions
- Integrate the SDK into your agent framework (works with LangChain, CrewAI, AutoGen, or any custom agent)
- Deploy OpenLeash as a Docker container for production use
- Use the interactive playground to test policy evaluation
For more depth, explore the AI agent authorization concepts, learn why we chose PASETO over JWT for proof tokens, or read about why AI agents need authorization in production systems. The full API reference and policy language documentation are available in the documentation.