AI systems read files, execute commands, call APIs, access databases, and interact with users. Every one of those capabilities is also an attack surface.
This guide covers 15 security domains that every developer working with LLMs and AI agents must understand. It is defensive only — focused on protecting your systems, not attacking others.
The 15 AI Security Domains
THREATS: DEFENSES:
┌─────────────────────┐ ┌─────────────────────┐
│ Prompt Injection │──→│ Least Privilege │
│ Indirect Injection │──→│ Input Validation │
│ Data Leakage │──→│ Data Minimization │
│ Tool Abuse │──→│ Tool Allowlists │
│ MCP Security │──→│ Sandboxing │
│ Excess Permissions │──→│ Human Approval │
│ Supply Chain │──→│ Monitoring │
│ Model Risks │──→│ Logging │
└─────────────────────┘ └─────────────────────┘
1. Prompt Injection
🔴 Threat Level: High
An attacker crafts input that overrides the system prompt, causing the model to ignore instructions and follow malicious ones instead.
How it works: The user input contains text that looks like system instructions, manipulating the model into performing unintended actions.
Defenses
- Use instruction hierarchy — system prompt always takes precedence
- Validate and sanitize all user input
- Never execute commands found in user messages
- Implement output filtering
2. Indirect Prompt Injection
🔴 Threat Level: High
Malicious instructions are embedded in documents, websites, emails, or repository files that the agent reads. The agent follows the embedded instructions without the user knowing.
Attack vectors:
- A README file contains hidden instructions for the agent
- A website the agent scrapes has injected commands
- An email the agent processes contains manipulation
- A Git commit message contains agent instructions
Defenses
- Treat all external content as untrusted
- Separate system instructions from external data
- Never execute commands found in external content
- Use content classification before processing
3. Data Leakage
🔴 Threat Level: High
Sensitive data (personal information, credentials, proprietary code) is sent to external LLM APIs or exposed through agent tool outputs.
Defenses
- Data minimization — send only necessary fields
- PII detection and redaction before LLM calls
- Field filtering on database queries
- Never log sensitive data in agent traces
4. Sensitive Information
🟡 Threat Level: Medium-High
Passwords, API keys, access tokens, financial data, health records, and confidential business information must never be sent to external LLM APIs without explicit authorization.
| Data Type | Risk | Action |
|---|---|---|
| Passwords / API keys | Critical | Never send to LLM |
| Health records | Critical | Redact or use local model |
| Financial data | Critical | Minimize, encrypt |
| Source code with secrets | High | Scan before sending |
| Personal names / emails | High | Minimize or pseudonymize |
| Business documents | High | Check vendor terms |
Defenses
- Never hard-code secrets in prompts
- Use environment variables for API keys
- Implement PII detection before LLM calls
- Use local models for sensitive data
5. Tool Abuse
🟡 Threat Level: Medium-High
An AI agent can use tools (file access, shell commands, API calls) to perform actions beyond its intended scope. Without restrictions, an agent might delete files, access unrelated repositories, or execute dangerous commands.
Defenses
- Tool allowlists — only approved tools available
- Argument validation — block injection in tool args
- Scope restrictions — limit file paths and commands
- Confirmation for high-risk operations
6. MCP Security
🟡 Threat Level: Medium-High
Model Context Protocol (MCP) servers expose tools and data to AI agents. An untrusted or misconfigured MCP server can provide excessive permissions, malicious tool descriptions, or access sensitive data.
Defenses
- Only connect to trusted MCP servers
- Implement per-tool authorization
- Log all MCP tool calls
- Use read-only access where possible
- Network isolation for MCP servers
7. Excessive Agent Permissions
🟡 Threat Level: Medium
An agent with root access, unrestricted filesystem access, or production credentials can cause catastrophic damage if compromised or if it makes a mistake.
BAD: Agent → Entire Computer → Everything
BETTER: Agent → Sandbox → Project Directory + Approved Tools Only
Defenses
- Least privilege — give agents only what they need
- Scoped filesystem access
- No production credentials for development agents
- Separate service accounts per agent
8. Insecure Outputs
🟡 Threat Level: Medium
AI-generated code may contain security vulnerabilities, hardcoded secrets, or insecure patterns. Blindly executing AI-generated code without review is dangerous.
Defenses
- Review all AI-generated code before merging
- Run static analysis on generated code
- Check for hardcoded secrets
- Test AI-generated code in sandbox first
9. Supply Chain
🟡 Threat Level: Medium
AI agents install packages, download models, and use third-party tools. Each dependency is a potential attack vector. Compromised model weights, malicious MCP servers, or poisoned training data can all be exploited.
Defenses
- Pin dependency versions
- Verify model checksums before loading
- Use private model registries
- Audit third-party MCP servers
- Scan AI-generated dependencies before installing
10. Model Risks
🟡 Threat Level: Medium
LLMs hallucinate, produce inconsistent outputs, and can be manipulated through carefully crafted inputs. Model behavior changes across versions, and fine-tuning can introduce unexpected behaviors.
Key Risks
- Hallucination: Model fabricates facts or citations
- Inconsistency: Same input produces different outputs
- Bias: Model reflects training data biases
- Version drift: Model behavior changes between versions
- Jailbreaking: Model bypasses safety restrictions
Defenses
- Evaluate model outputs against ground truth
- Pin model versions in production
- Implement output validation
- Monitor for behavioral changes across updates
11. Secrets Management
🔴 Threat Level: High
API keys, database passwords, SSH credentials, and cloud tokens must never be exposed to AI agents. If an agent can access environment variables, it may leak secrets through tool outputs or logs.
Defenses
- Never hard-code secrets in prompts or code
- Use secret managers (HashiCorp Vault, AWS Secrets Manager)
- Scoped credentials — agents get only what they need
- Short-lived credentials with automatic rotation
- Secret scanning in repositories
12. Logging
🟢 Defense: Essential
Proper logging creates an audit trail of agent actions. Without it, you cannot investigate incidents, detect misuse, or prove compliance.
What to Log
- Agent actions and tool calls
- Model calls (tokens, latency, version)
- Errors and recoveries
- Human approvals and overrides
- Policy violations
What NOT to Log
- API keys or credentials
- Complete user messages with PII
- Full LLM responses with sensitive data
13. Monitoring
🟢 Defense: Essential
Continuous monitoring detects anomalies, security incidents, and performance degradation in real time.
| Metric | Alert Threshold | Why |
|---|---|---|
| Error rate | > 10% of tool calls | Agent failing repeatedly |
| Cost per trace | > 3× average | Runaway token usage |
| Latency p95 | > 5 seconds | Performance degradation |
| Secrets in output | Any occurrence | Data leakage |
| Unhandled errors | Any occurrence | Potential vulnerability |
14. Human Approval
🟢 Defense: Critical
For high-risk actions — production deployments, credential changes, network modifications, database operations — the agent should pause and request human confirmation before executing.
LOW RISK: Read repository → Auto-execute
MEDIUM: Modify source code → Log + review
HIGH: Change infrastructure → Pause + approve
CRITICAL: Production deploy → Human must approve
Defenses
- Classify actions by risk level
- Require human approval for HIGH and CRITICAL
- Implement timeout for pending approvals
- Log all approval decisions
15. Sandboxing
🟢 Defense: Essential
Run AI agents in isolated environments with limited filesystem access, restricted network, and scoped permissions. A sandbox prevents an agent from affecting the host system.
Sandbox Architecture
- Filesystem: Agent sees only its workspace, not the host
- Network: Restrict outbound connections to approved endpoints
- Permissions: Run as non-root, limited capabilities
- Temporary: Ephemeral environments that are destroyed after use
Complete AI Security Checklist
🛡️ 30-Point AI Security Checklist
- Prompt Security
- ☐ System prompt enforces instruction hierarchy
- ☐ User input is treated as data, not instructions
- ☐ External content is treated as untrusted
- ☐ Output filtering is implemented
- Data Protection
- ☐ PII detection runs before LLM calls
- ☐ Data minimization applied — only necessary fields sent
- ☐ Sensitive data never sent to external APIs
- ☐ Local models used for sensitive workloads
- Tool Security
- ☐ Tool allowlists defined
- ☐ Tool arguments validated
- ☐ Filesystem access scoped to workspace
- ☐ Shell commands restricted to safe operations
- MCP Security
- ☐ Only trusted MCP servers connected
- ☐ Per-tool authorization implemented
- ☐ MCP tool calls logged
- Permissions
- ☐ Least privilege applied to all agents
- ☐ No production credentials for development agents
- ☐ Separate service accounts per agent
- Secrets
- ☐ No hard-coded secrets
- ☐ Secret managers used for credentials
- ☐ Secret scanning in repositories
- Monitoring & Logging
- ☐ Agent actions logged with request IDs
- ☐ Sensitive data excluded from logs
- ☐ Alerts configured for anomalies
- Human Oversight
- ☐ Human approval for high-risk actions
- ☐ Risk classification for all agent actions
- Sandboxing
- ☐ Agent runs in isolated environment
- ☐ Network restrictions in place
Related BestWordz Tools
Practice security concepts with these tools:
🔐 Password Generator — Generate secure passwords 🔐 Password Strength Checker — Test password security 🔄 Base64 Encoder — Encode data safely 🔄 Base64 Decoder — Decode Base64 data 🔗 URL Encoder — Encode URLs for safe transmission 🔗 URL Decoder — Decode encoded URLs 🔍 Regex Tester — Test input validation patterns 📋 JSON Formatter — Format and validate JSON data 🆔 UUID Generator — Generate unique identifiersRelated BestWordz Articles
AI Security Fundamentals
🛡️ AI Security Risks in 2026: Securing Coding Agents, LLMs and Agentic Workflows 🛡️ AI Coding Agent Security Checklist: Claude Code, Cursor and Beyond 🛡️ Is AI-Generated Code Secure? A Developer Security ChecklistPrompt Injection
💉 Prompt Injection Explained: How AI Applications Can Be Manipulated 💉 Indirect Prompt Injection: When Websites and Documents Attack AI AgentsData & Privacy
🔒 AI Privacy by Design: How Developers Should Minimize Data Sent to LLMs 🔑 Protecting API Keys and Secrets in AI Coding Workflows 🔑 Secrets Management for Developers: From .env Files to Secret Managers 🔒 RAG Security: Protecting Vector Stores and Preventing Data LeakageMCP & Tools
🔌 MCP Security: The Complete Developer Checklist 🔌 MCP vs Function Calling vs Plugins: Understanding AI Tool IntegrationSupply Chain
📦 AI Agent Supply-Chain Security: Protecting Models, Tools, Skills and DependenciesMonitoring & Observability
📊 AI Agent Observability Explained: Monitoring What Your Agent Is Doing 📊 LLM Observability: Monitoring and Debugging AI Systems in Production 📋 AI Audit Trails Explained: What Should Developers Log?Safe Agent Usage
✅ How to Use AI Coding Agents Safely: A Practical Developer Guide 🔍 How to Debug AI Agents: A Practical Developer GuideVulnerability Detection
🐛 AI-Assisted Vulnerability Detection: Can Machine Learning Find Security Bugs? 💉 SQL Injection Explained and PreventedInfrastructure Security
🐳 Docker Security for Developers: 15 Practical RulesCryptography
🔐 Hashing vs Encryption vs Encoding: What is the Difference?Regulation
⚖️ AI Regulation for Developers: Data Privacy, Transparency and Local AI InfrastructureExplore BestWordz Cybersecurity
For more cybersecurity content, tools, and tutorials:
🛡️ BestWordz Cybersecurity Category — All security articles and toolsFAQ
Q: What is the #1 AI security risk?
A: Prompt injection (direct and indirect). It is the most common attack vector and can lead to data leakage, tool abuse, and system compromise.
Q: Can I make an AI system completely secure?
A: No. Security is about risk reduction, not elimination. Apply defense in depth: multiple layers of protection so that if one fails, others catch the issue.
Q: Should I use a local model for sensitive data?
A: Local models reduce data transfer risks but do not eliminate all obligations. You still need to handle personal data, consent, and security properly.
Q: How often should I audit my AI system?
A: At minimum: before deployment, after major changes, and quarterly. Continuous monitoring should run 24/7.
Q: What is the difference between AI security and AI safety?
A: Security protects against malicious attacks (prompt injection, data theft). Safety protects against unintended harm (bias, hallucination, unsafe outputs). Both are necessary.
Q: Do I need all 15 defenses?
A: Not necessarily. Prioritize based on your threat model: what data you handle, what tools the agent uses, and what the impact of a breach would be. Start with the highest-risk domains for your use case.
Further Reading
- AI Security Risks in 2026
- Prompt Injection Explained
- MCP Security Checklist
- AI Audit Trails
- AI Privacy by Design
- How to Use AI Coding Agents Safely
Continue Learning: Start with AI Security Risks overview, then dive into prompt injection, secure your MCP servers, implement audit trails, and apply privacy by design.
Discuss this topic on BestWordz Community.