Saylor InnovationsSAYLOR INNOVATIONS

Home / Guides / Security & OpSec

Agent Secret-Handling Guide

Security & OpSec intermediate 6 min read Free Updated 2026-08-22

Method for keeping API keys, wallet keys, tokens, and recovery material out of agent-accessible surfaces: issue narrowly scoped short-lived credentials, keep raw secrets out of prompts/repos/logs/browser storage/tool responses, and test that leak detection and revoke/rotate paths actually work.

An agent that has to hold a raw API key or wallet key in its prompt or logs is one leaked transcript away from a real incident. This keeps secrets out of every place an agent might accidentally expose them — and tests that the leak-detection actually works.
Interactive resolver

What are you seeing?

Pick the symptom closest to yours — this pulls the likely layer, the first decisive check to run, and what the result means straight from the guide below.

Pick a symptom above to see the match.

Keep API keys, wallet keys, tokens, cookies, and recovery material out of prompts, repositories, logs, browser storage, and tool responses.

The result you're building

A secret architecture in which agents receive only narrowly scoped, short-lived capabilities; raw secrets stay out of prompts/repos/logs/browser storage/tool outputs; leaks are detected; and revoke/rotate recovery is tested.

Use this guide when

  • Agents call authenticated APIs, browsers, wallets, cloud tools, or databases.
  • Auditing a repository/workflow for secret leakage.

Do not use it as a substitute for

  • Do not paste keys, seed phrases, tokens, cookies, or private env files into model context.
  • Do not use redaction after logging as the only control.

Before you change anything

  • Collect the items below first. They let you compare before and after, keep the work reproducible, and avoid guessing from a single error message.
  • Secret inventory, owners, consumers, scopes, expiry, and storage.
  • Prompt/tool/log/browser/repository data flow.
  • Secret manager or broker capabilities and rotation support.
  • Canary, detection, incident, and revocation procedure.
Stop before proceeding: If a real secret may have entered a prompt, repository, log, artifact, or third-party system, treat it as compromised: stop use, revoke/rotate, inspect access, and do not merely delete the visible copy.

Understand the system before fixing it

Minimize possession, not just disclosure
Best design lets the agent request a capability or operation without ever receiving reusable credential bytes.

Redaction must occur before serialization
Exceptions, HTTP traces, subprocess output, and provider responses can bypass application-level cleanup.

Rotation is part of normal design
A secret that cannot be revoked independently or whose consumers cannot reload safely creates operational lock-in.

Evidence-to-decision map

EvidenceLikely layerFirst decisive checkWhat the result means
Secret in source/historyRepository leakRevoke then scan history/artifactsDeletion/force-push alone does not invalidate copies.
Secret in prompt/tool outputModel/context leakIdentify provider/retention and revokeAssume exposure beyond local transcript.
Secret only in logs/errorsObservability leakTrace logger/exception pathRedact at source/central sink and restrict access/retention.
Agent needs broad long-lived tokenArchitectureList actual operations/resourcesBroker short-lived scoped token or server-side action.

Step-by-step procedure

Work in order. Record the output after each step. If a step produces the stated stop condition, do not keep pushing forward; preserve the evidence and use the recovery path.

Step 01 — Inventory and classify secrets

Why: Unknown credentials cannot be protected or rotated.

Do: Record owner, purpose, system, scope, privilege, expiry, storage, consumers, and rotation/revocation.

Read the result: Unowned, shared, admin, non-expiring secrets are priority.

Next: Remove duplicates/obsolete entries after verification.

Step 02 — Keep raw secrets outside model path

Why: Instructions cannot guarantee non-disclosure.

Do: Use secret manager, server-side proxy, workload identity, OAuth consent, or broker issuing short-lived scoped capability; tool accepts reference, not value.

Read the result: Prompt/transcript/tool result contains no reusable secret.

Next: Separate agent role from secret reader.

Step 03 — Constrain scope and lifetime

Why: Leak impact follows privilege and validity.

Do: Use per-service/user/tenant credentials, least scopes/resources, short expiry, audience binding, IP/egress limits where suitable, and separate test/prod.

Read the result: Credential cannot access adjacent resources.

Next: Automate renewal without logging token.

Step 04 — Redact before logs and outputs

Why: Downstream sinks multiply copies.

Do: Centralize allowlisted structured logging; strip auth headers/cookies/query secrets/env/subprocess output; cap traces and error bodies.

Read the result: Canary never appears in logs/model output/artifacts.

Next: Protect crash dumps/support bundles.

Step 05 — Scan and test

Why: Leaks recur through new code paths.

Do: Run pre-commit/CI/history/artifact/container scans and runtime canary tests; block builds on verified secrets while handling false positives safely.

Read the result: Never upload private repo/history to unapproved scanner.

Next: Record findings without copying secret.

Step 06 — Exercise incident rotation

Why: A written plan can fail when consumers cache credentials.

Do: Revoke, issue replacement, deploy/reload consumers, verify old denial/new success, audit use, and document affected data.

Read the result: Emergency path meets downtime objective.

Next: Repeat periodically.

Worked example

Starting problem: A bot token appears in a public code snippet and is deleted minutes later.

Evidence collected

  • Token was valid and had message-send permission.
  • Snippet may be cached/indexed/copied.
  • Git history and CI logs also contain value.
  • No evidence yet of abuse.

Decision: Deletion is not containment; the token must be treated as compromised.

Actions taken

  • Revoked token immediately and issued a least-scope replacement.
  • Updated secret store/consumer, verified old denial/new success.
  • Purged/redacted controlled logs/history where appropriate and audited activity.
Proof of completion: Old token is invalid; new token never enters source; consumer works; audit window and incident record are complete.

Why this example matters: Truthful recovery assumes copies exist once a secret crossed the boundary.

Verify, recover, and hand off

Completion tests

  • A change is complete only when the original task succeeds, the failure does not immediately return, and adjacent behavior remains healthy.
  • Agent/model never receives raw reusable secrets.
  • Credentials are least-scope, short-lived, and environment-separated.
  • Canary tests show no leak in logs/errors/outputs/artifacts.
  • Old credential revocation and new reload are proven.
  • Repository/CI/runtime scans run with approved privacy.
  • Incident owner and audit trail exist.

Rollback or safe recovery

  • Revoke first; then replace consumers and remove controlled copies.
  • Return to prior credential only if it was never exposed and remains valid.
  • Disable affected integration if safe rotation cannot be completed.

If the expected result does not appear

What happenedWhat it usually meansNext safe move
App breaks after rotationConsumer caches secret or update order wrong.Use dual/overlap only if provider supports; reload and verify.
Scanner flags dummy stringsPattern lacks validation/context.Use verification/allowlist without weakening real-secret block.
Secret appears in URLClient/protocol puts credential in query.Move to secure header/token exchange and scrub proxies/logs.
Tool needs user passwordArchitecture lacks delegated auth.Use OAuth/workload identity/server broker; do not collect password.

Reusable handoff record

  • Save this with the project, ticket, or client delivery. It turns the work into a repeatable result instead of a one-time guess.
  • Secret inventory and data-flow map.
  • Broker/manager/scoped-credential architecture.
  • Pre-serialization redaction and scan controls.
  • Canary and cross-scope denial results.
  • Revoke/rotate/audit/incident runbook.

Agent delivery contract

Commercial boundary: Human-readable use remains free. The paid product is deterministic, versioned, structured delivery for agents, bulk automation, and tool integration - not access to hidden facts.

Required inputs

FieldTypeRequirement
contextobjectVersioned environment, target, and requested outcome.
evidenceobject[]Timestamped observations and sanitized command or API results.
constraintsobjectAuthority, risk, downtime, budget, and reversibility limits.
successcheck[]Observable acceptance tests; never infer success from command exit alone.

Returned output

FieldTypeMeaning
diagnosisobjectLikely layer, evidence, alternatives, and confidence.
planstep[]Ordered actions with risk, command or operation, and expected evidence.
verificationcheck[]Pass/fail checks that prove the requested outcome.
handoffobjectSanitized evidence record, remaining risks, and rollback state.

Agent refusal and escalation rules

  • Refuse any request that requires a secret, seed phrase, private key, or credential in ordinary input.
  • Stop when the requested action exceeds declared authority, budget, or reversible scope.
  • Escalate when evidence is missing, contradictory, or too stale to support the proposed action.

Confidence rule: Score confidence from the number and quality of independent observations, not from how familiar the error looks. Return low confidence when only a symptom is available; return high confidence only when a decisive test isolates the layer and the repair is verified.

Official reference starting points