Agent Guardrails Docs

Quick Start

Get from zero to a working guarded agent in under 10 minutes.

Prerequisites

  • Rust 1.75+ (rustc --version)
  • Solana CLI 1.18+ (solana --version)
  • Anchor CLI 0.30.1 (anchor --version)
  • Node.js 20+ (node --version)
  • pnpm 9+ (pnpm --version)

1. Clone & Setup

terminal
git clone https://github.com/AgentGuards/agent-guardrails.git
cd agent-guardrails
git config core.hooksPath .githooks

2. Build the Program

terminal
cd program
anchor build
bash ../scripts/sync-sdk.sh
The sync script copies the IDL and TypeScript client to server/ and dashboard/.

3. Deploy to Devnet

terminal
solana config set --url devnet
solana airdrop 5
cd program
anchor deploy --provider.cluster devnet

Copy the program ID from the output. You will need it when configuring the server and dashboard environment variables.

4. Create Your First Policy

create-policy.ts
import { GuardrailsClient } from '@agentguards/sdk';
import { AnchorProvider } from '@coral-xyz/anchor';
import { PublicKey, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js';

const provider = AnchorProvider.env();
const client = new GuardrailsClient(provider);

// Generate an agent session key
const agentKeypair = Keypair.generate();

// Create a policy
const txSig = await client.initializePolicy(agentKeypair.publicKey, {
  allowedPrograms: [
    new PublicKey('JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4'), // Jupiter
    new PublicKey('11111111111111111111111111111111'),              // System Program
  ],
  maxTxLamports: BigInt(2 * LAMPORTS_PER_SOL),      // 2 SOL per tx
  maxTxTokenUnits: BigInt(0),
  dailyBudgetLamports: BigInt(20 * LAMPORTS_PER_SOL), // 20 SOL daily
  sessionExpiry: BigInt(Math.floor(Date.now() / 1000) + 86400 * 30), // 30 days
  squadsMultisig: null,
  escalationThreshold: BigInt(0),
  authorizedMonitors: [],
});

console.log('Policy created:', txSig);

5. Fund the Policy PDA

Funds must be deposited to the policy PDA, not the agent keypair. The agent is only an authorized signer — the policy PDA holds all SOL and enforces spending constraints.

fund-policy.ts
const [policyPda] = client.findPolicyPda(provider.wallet.publicKey, agentKeypair.publicKey);

// Transfer SOL to policy PDA
const tx = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: provider.wallet.publicKey,
    toPubkey: policyPda,
    lamports: 10 * LAMPORTS_PER_SOL,
  })
);
await provider.sendAndConfirm(tx);

6. Execute a Guarded Transaction

guarded-execute.ts
const [policyPda] = client.findPolicyPda(owner, agentKeypair.publicKey);
const [trackerPda] = client.findTrackerPda(policyPda);

const txSig = await client.guardedExecute(
  agentKeypair,
  policyPda,
  trackerPda,
  SystemProgram.programId,
  {
    instructionData: Buffer.from([2, 0, 0, 0, ...]), // transfer ix
    amountHint: BigInt(1 * LAMPORTS_PER_SOL),
    inputAccountIndex: null,
  },
  [{ pubkey: destinationPubkey, isSigner: false, isWritable: true }]
);

Next Steps