Sol.College

Full lesson

agent-guardrails

Agent guardrails

What it does

From the project README:

250,000+ AI agents operate on Solana today. Most hold unconstrained keys — if compromised, there's nothing on-chain stopping them from draining their treasury. Step Finance lost $40M to exactly this kind of failure.
Original
AgentGuards/agent-guardrails
SuperStack fork
Blockchains/agent-guardrails @ 2646aa7
Stars
0
Last push (original)
2026-05-08
Languages
TypeScript, Rust, HTML, Shell, CSS, JavaScript
Detected stack
AnchorNext.jsweb3.js
Categories
AI & Agents
Licence
Apache-2.0
Homepage
https://agentguards.vercel.app

Architecture

295 source files. By extension: .ts ×152, .tsx ×121, .rs ×20, .js ×2.

Top-level directorySource files
dashboard166
server65
landingPage34
program28
sdk2

On-chain programs: program/programs/guardrails

Dapp: devnet deploy pending

⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/agent-guardrails/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.

Key code, explained

Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.

AgentGuards/agent-guardrails · program/programs/guardrails/src/instructions/rotate_agent_key.rs L73–96 @ 2646aa7 · Apache-2.0 · original
     /// The new SpendTracker PDA linked to the new policy.    #[account(        init,        payer = owner,        space = SPEND_TRACKER_SIZE,        seeds = [b"tracker", new_policy.key().as_ref()],        bump,    )]    pub new_tracker: Account<'info, SpendTracker>,     pub system_program: Program<'info, System>,} // ---------------------------------------------------------------------------// Handler// --------------------------------------------------------------------------- pub fn handler(ctx: Context<RotateAgentKey>, args: RotateAgentKeyArgs) -> Result<()> {    let clock = Clock::get()?;     // 1. Validate: new agent must differ from current    require!(        args.new_agent != ctx.accounts.old_policy.agent,
  1. Line 76 init,: Creates and pays for a new account. Space and payer must be specified.
  2. Line 79 seeds = [b"tracker", new_policy.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  3. Line 80 bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  4. Line 92 let clock = Clock::get()?;: Reads on-chain time from the Clock sysvar.
  5. Line 95 require!(: An explicit validation that aborts the instruction with an error.
AgentGuards/agent-guardrails · program/programs/guardrails/src/instructions/update_policy.rs L13–36 @ 2646aa7 · Apache-2.0 · original
use crate::errors::GuardrailsError;use crate::state::policy::{PermissionPolicy, MAX_ALLOWED_PROGRAMS, MAX_AUTHORIZED_MONITORS}; // ---------------------------------------------------------------------------// Accounts// --------------------------------------------------------------------------- #[derive(Accounts)]pub struct UpdatePolicy<'info> {    /// The policy owner. Must sign. The `has_one` constraint on `policy`    /// verifies that this signer matches the stored `policy.owner`.    pub owner: Signer<'info>,     /// The PermissionPolicy PDA to update. Only the stored owner can modify it.    /// The `has_one = owner` constraint enforces ownership — Anchor checks    /// `policy.owner == owner.key()` and returns ConstraintHasOne on mismatch.    #[account(        mut,        seeds = [b"policy", policy.owner.as_ref(), policy.agent.as_ref()],        bump = policy.bump,        has_one = owner,    )]    pub policy: Account<'info, PermissionPolicy>,}
  1. Line 22 /// The policy owner. Must sign. The `has_one` constraint on `policy`: Checks that a stored pubkey field matches the passed account.
  2. Line 24 pub owner: Signer<'info>,: Requires this account to have signed the transaction.
  3. Line 31 seeds = [b"policy", policy.owner.as_ref(), policy.agent.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  4. Line 32 bump = policy.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
AgentGuards/agent-guardrails · program/programs/guardrails/src/instructions/close_policy.rs L13–36 @ 2646aa7 · Apache-2.0 · original
 // ---------------------------------------------------------------------------// Accounts// --------------------------------------------------------------------------- #[derive(Accounts)]pub struct ClosePolicy<'info> {    /// Only the policy owner can close it.    #[account(mut)]    pub owner: Signer<'info>,     /// The PermissionPolicy PDA to close. Must be paused.    #[account(        mut,        seeds = [b"policy", policy.owner.as_ref(), policy.agent.as_ref()],        bump = policy.bump,        has_one = owner,    )]    pub policy: Box<Account<'info, PermissionPolicy>>,     /// The SpendTracker PDA to close.    #[account(        mut,        seeds = [b"tracker", policy.key().as_ref()],
  1. Line 22 pub owner: Signer<'info>,: Requires this account to have signed the transaction.
  2. Line 27 seeds = [b"policy", policy.owner.as_ref(), policy.agent.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  3. Line 28 bump = policy.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  4. Line 29 has_one = owner,: Checks that a stored pubkey field matches the passed account.
AgentGuards/agent-guardrails · program/programs/guardrails/src/instructions/pause_agent.rs L13–36 @ 2646aa7 · Apache-2.0 · original
use crate::state::policy::PermissionPolicy; // ---------------------------------------------------------------------------// Accounts// --------------------------------------------------------------------------- #[derive(Accounts)]pub struct PauseAgent<'info> {    /// The caller requesting the pause. Must be either the policy owner or    /// one of the policy's authorized_monitors. Validated in handler body    /// (not via has_one, because monitors are a Vec, not a single field).    pub caller: Signer<'info>,     /// The PermissionPolicy PDA to pause. Mutable because is_active,    /// paused_by, and paused_reason fields are modified.    #[account(        mut,        seeds = [b"policy", policy.owner.as_ref(), policy.agent.as_ref()],        bump = policy.bump,    )]    pub policy: Account<'info, PermissionPolicy>,} // ---------------------------------------------------------------------------
  1. Line 23 /// (not via has_one, because monitors are a Vec, not a single field).: Checks that a stored pubkey field matches the passed account.
  2. Line 24 pub caller: Signer<'info>,: Requires this account to have signed the transaction.
  3. Line 30 seeds = [b"policy", policy.owner.as_ref(), policy.agent.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  4. Line 31 bump = policy.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.

How to run, build and test

These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.

DirectoryCommandRuns
dashboardnpm run devnext dev
dashboardnpm run startnext start
dashboardnpm run buildnext build
dashboardnpm run testvitest run
dashboardnpm run lintnext lint
servernpm run devtsx watch src/index.ts
servernpm run starttsx src/index.ts
servernpm run buildprisma generate
servernpm run testvitest run
programnpm run buildanchor build
programnpm run testanchor test --skip-local-validator --skip-deploy
programnpm run deployanchor deploy
sdknpm run buildtsc
landingPagenpm run devnext dev
landingPagenpm run startnext start
landingPagenpm run buildnext build

What you could build from it