Skip to content

Security Best Practices

Security is critical when deploying AI agents to production. This guide covers essential practices to keep your agents, data, and users safe.


Principle: Assume breach. Design systems that remain secure even if one component is compromised.

Key Principles:

  1. Least Privilege - Minimum permissions needed
  2. Defense in Depth - Multiple security layers
  3. Zero Trust - Verify everything, trust nothing
  4. Fail Secure - Errors should deny access, not grant it

Do’s ✅

  • Create org API keys in Settings → API Keys (sk_live_...)
  • Store third-party tokens only in Integrations connection setup (encrypted)
  • Use environment variables in your own apps that call the Auteryn API — never commit keys to git

Don’ts ❌

Best Practices:

  • Use OAuth over API keys when available
  • Request minimum scopes needed
  • Refresh tokens before expiry
  • Revoke unused tokens

For user-facing agents:

# Verify user identity
if not user.is_authenticated():
return "Please log in first"
# Check permissions
if not user.has_permission("view_data"):
return "Access denied"

PII (Personally Identifiable Information):

# ❌ Bad: Logging PII
logger.info(f"User email: {user.email}")
# ✅ Good: Redact PII
logger.info(f"User: {user.id}")
# ✅ Good: Hash PII
import hashlib
hashed = hashlib.sha256(user.email.encode()).hexdigest()
logger.info(f"User hash: {hashed[:8]}")

Credit Card Data:

At Rest:

# Auteryn encrypts all data automatically
# But for extra sensitive data:
from cryptography.fernet import Fernet
key = agent.get_secret("ENCRYPTION_KEY")
cipher = Fernet(key)
# Encrypt
encrypted = cipher.encrypt(b"sensitive data")
# Decrypt
decrypted = cipher.decrypt(encrypted)

In Transit:

  • Always use HTTPS for APIs
  • Verify SSL certificates
  • Use TLS 1.3 minimum

SQL Injection Prevention:

# ❌ Bad: String concatenation
query = f"SELECT * FROM users WHERE email = '{user_input}'"
# ✅ Good: Parameterized queries
query = "SELECT * FROM users WHERE email = %s"
cursor.execute(query, (user_input,))

XSS Prevention:

# ❌ Bad: Raw HTML
html = f"<div>{user_input}</div>"
# ✅ Good: Escape HTML
from html import escape
html = f"<div>{escape(user_input)}</div>"

Command Injection Prevention:

# ❌ Bad: Shell injection risk
os.system(f"ls {user_input}")
# ✅ Good: Use subprocess with list
import subprocess
subprocess.run(["ls", user_input])
def validate_email(email):
import re
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if not re.match(pattern, email):
raise ValueError("Invalid email")
return email
# Use validation
try:
email = validate_email(user_input)
except ValueError:
return "Please provide a valid email"

Define roles and permissions:

roles = {
"admin": ["read", "write", "delete", "manage_users"],
"editor": ["read", "write"],
"viewer": ["read"]
}
# Check permission
if "write" not in user.permissions:
return "Access denied"

Avoid: Granting write/admin scopes on GitHub, Google, or Slack when the agent only reads data.

Prefer: Read-only connection scopes in Integrations, then add write scopes only when the agent must create or update resources.


Store integration tokens in Integrations → [connection] setup — they are encrypted at rest. Never paste API keys into agent instructions or commit them to git.


Do log:

  • Authentication attempts
  • Permission checks
  • Data access
  • Configuration changes
  • Integration calls
  • Errors and exceptions

Don’t log:

  • Passwords or API keys
  • Credit card numbers
  • PII (unless necessary and encrypted)
  • Full request/response bodies
import logging
logger.info({
"event": "data_access",
"user_id": user.id,
"resource": "customer_data",
"action": "read",
"timestamp": "2026-04-02T10:15:23Z",
"ip_address": request.ip,
"result": "success"
})

User Rights:

  • Right to access data
  • Right to deletion
  • Right to portability
  • Right to rectification

Implementation:

# Data export
data = agent.export_user_data(user_id)
# Data deletion
agent.delete_user_data(user_id)
# Anonymization
agent.anonymize_user_data(user_id)

Set retention policies:

agent.configure_retention(
logs="30d",
snapshots="90d",
conversations="1y",
analytics="2y"
)

  1. Detect - Monitoring alerts on issue
  2. Contain - Isolate affected systems
  3. Investigate - Determine root cause
  4. Remediate - Fix the issue
  5. Recover - Restore normal operations
  6. Review - Post-mortem and improvements

  • All secrets in environment variables
  • Input validation on all user inputs
  • SQL injection prevention
  • XSS prevention
  • CSRF protection
  • Rate limiting configured
  • Audit logging enabled
  • Error messages don’t leak info
  • HTTPS only
  • Security headers configured
  • Review audit logs weekly
  • Rotate secrets quarterly
  • Update dependencies monthly
  • Security training for team
  • Incident response drills
  • Penetration testing annually


  • Is Auteryn SOC 2 compliant? Contact security@auteryn.ai for current compliance status and enterprise requirements.
  • Where is data stored? US or EU regions (you choose).
  • Can I use my own encryption keys? Yes (Enterprise plan).
  • Do you support HIPAA? Yes, with BAA (Enterprise plan).
  • How do you handle security incidents? 24/7 monitoring, immediate response, transparent communication.

View all FAQs →