1. What makes an AI agent different?
A normal application follows predefined code paths. An AI agent can decide which tool to call next based on context. If the agent can read files, call APIs, execute commands or change infrastructure, its security boundary is no longer just the application code.
The user asks the agent to solve a problem.
The agent may choose APIs, files, databases or commands.
Bad input, wrong tool selection, retries and leaked secrets can combine.
2. Real-time example: AI Operations Agent
Imagine an engineering team builds an agent called OpsAssist. It reads application logs, identifies an incident, creates a ticket and can restart a service after approval.
| Capability | Required? | Security decision |
|---|---|---|
| Read application logs | Yes | Read-only log account; sensitive fields redacted. |
| Create incident ticket | Yes | Scoped API key limited to ticket creation. |
| Restart service | Sometimes | Human approval required. |
| Delete database | No | No permission at all. |
| Read production secrets | No | Explicitly blocked. |
3. Secure reference architecture
A small production agent can use a simple separation between the public entry point, private worker, internal services and human approval.
For larger systems: split the agent into separate VMs/containers such as agent-web, agent-worker, agent-db and agent-monitor.
4. Build the secure agent step by step
Define the permission boundary
Write a short capability contract before writing code.
Agent: OpsAssist
READ:
- application logs
- service health
- incident tickets
WRITE:
- create incident ticket
- add ticket comment
APPROVAL REQUIRED:
- restart service
- change configuration
DENY:
- database deletion
- production credential access
- arbitrary shell executionCreate separate credentials
Use one credential per integration. Prefer read-only and narrowly scoped permissions.
# Never:
GITHUB_TOKEN=personal-admin-token
# Better:
GITHUB_AGENT_TOKEN=scoped-read-only-token
TICKETING_AGENT_TOKEN=scoped-ticket-token
Keep secrets outside Git and rotate any credential that is exposed.
Run with least privilege
Do not run the agent as root unless there is a documented reason. Restrict filesystem access, network access and process capabilities.
Separate test and production
Use different credentials, databases, API endpoints and approval rules. A test agent must never accidentally inherit production credentials.
Add failure controls
Set timeouts, retry limits, rate limits and circuit breakers. If the agent cannot establish that an action is safe, stop rather than guessing.
5. Interactive prompt-injection lab
Prompt injection occurs when untrusted content tries to manipulate the agent's behavior. Test the example below.
6. Human approval for dangerous actions
Let the agent prepare a risky action, but require a person to approve it.
7. Logging and monitoring
When an agent makes a mistake, you need enough information to reconstruct what happened without creating another data leak.
| Log field | Example | Do not log |
|---|---|---|
| Request ID | req-8f21 | — |
| Tool | restart_service | Secret token |
| Target | analytics-api | Private customer data |
| Approval | approved_by=human | Passwords |
| Result | success | Full sensitive payload |
8. VPS / container security baseline
- Use a dedicated runtime for production agents.
- Run under a non-root account where possible.
- Allow only required inbound ports.
- Keep databases off the public internet.
- Use private networking for internal services.
- Keep secrets in a secret manager or protected environment configuration.
- Patch the operating system and runtime regularly.
- Enable backups for stateful data.
- Set CPU, RAM, disk and process monitoring.
- Keep test and production credentials completely separate.
9. Interactive AI Agent Security Assessment
Check each control. The score is a quick engineering indicator, not a formal security certification.
Start by checking the controls you already have.
10. Production readiness checklist
| Area | Minimum question |
|---|---|
| Identity | Who can invoke the agent and who can approve risky actions? |
| Authorization | What is the smallest permission set needed? |
| Secrets | Where are credentials stored, rotated and revoked? |
| Prompt injection | Can untrusted documents override agent instructions? |
| Isolation | What happens if the agent is compromised? |
| Network | Which ports and destinations are actually required? |
| Observability | Can you reconstruct every important tool action? |
| Human control | Which actions must stop for approval? |
| Recovery | Can the system recover from bad output or a failed deployment? |
Key takeaway
The practical pattern is: least privilege + isolated runtime + protected secrets + untrusted-input handling + human approval + audit logs + monitoring + controlled network access + recovery.
Start with one small agent, define its permissions, isolate it, observe it, and expand capabilities only when there is a clear business need.
Source & adaptation note
This tutorial is an original, expanded and interactive teaching version based on the concepts in HYEHOST's article “AI Agent Security: How to Host Autonomous Tools Without Creating a Shadow AI Risk”, published July 8, 2026. It reorganizes the ideas into a hands-on engineering tutorial and adds an illustrative OpsAssist example and browser-based exercises.
Source: HYEHOST — AI Agent Security.