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 directory | Source files |
|---|---|
dashboard | 166 |
server | 65 |
landingPage | 34 |
program | 28 |
sdk | 2 |
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.
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,- Line 76
init,: Creates and pays for a new account. Space and payer must be specified. - 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. - Line 80
bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 92
let clock = Clock::get()?;: Reads on-chain time from the Clock sysvar. - Line 95
require!(: An explicit validation that aborts the instruction with an error.
program/programs/guardrails/src/instructions/update_policy.rs L13–36 @ 2646aa7 · Apache-2.0 · originaluse 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>,}- Line 22
/// The policy owner. Must sign. The `has_one` constraint on `policy`: Checks that a stored pubkey field matches the passed account. - Line 24
pub owner: Signer<'info>,: Requires this account to have signed the transaction. - 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. - Line 32
bump = policy.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
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()],- Line 22
pub owner: Signer<'info>,: Requires this account to have signed the transaction. - 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. - Line 28
bump = policy.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 29
has_one = owner,: Checks that a stored pubkey field matches the passed account.
program/programs/guardrails/src/instructions/pause_agent.rs L13–36 @ 2646aa7 · Apache-2.0 · originaluse 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>,} // ---------------------------------------------------------------------------- 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. - Line 24
pub caller: Signer<'info>,: Requires this account to have signed the transaction. - 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. - 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.
| Directory | Command | Runs |
|---|---|---|
dashboard | npm run dev | next dev |
dashboard | npm run start | next start |
dashboard | npm run build | next build |
dashboard | npm run test | vitest run |
dashboard | npm run lint | next lint |
server | npm run dev | tsx watch src/index.ts |
server | npm run start | tsx src/index.ts |
server | npm run build | prisma generate |
server | npm run test | vitest run |
program | npm run build | anchor build |
program | npm run test | anchor test --skip-local-validator --skip-deploy |
program | npm run deploy | anchor deploy |
sdk | npm run build | tsc |
landingPage | npm run dev | next dev |
landingPage | npm run start | next start |
landingPage | npm run build | next build |
What you could build from it
- Fork the SuperStack copy and extend it within the AI & Agents gaps listed on the idea page.
- Learn the pattern first: AI agents on Solana
- Learn the pattern first: Building and sending transactions from a client