2026-01-19 · Authensor

How to Secure AI Agents on Microsoft Azure

SafeClaw by Authensor adds deny-by-default action gating to AI agents running on Microsoft Azure. Every action your agent attempts — file operations, network requests, shell commands — is intercepted and checked against your YAML policy before execution. It works with both Claude and OpenAI-powered agents. Install with npx @authensor/safeclaw and enforce least-privilege at the application layer across Azure App Service, AKS, Container Apps, and Functions.

Prerequisites

Step 1 — Install SafeClaw

npx @authensor/safeclaw

Zero dependencies, MIT-licensed, 446 tests. SafeClaw scaffolds a policy file and integrates into your agent's runtime.

Step 2 — Write an Azure-Specific Policy

version: 1
defaultAction: deny

rules:
- action: "file:read"
path: "/home/site/wwwroot/**"
effect: allow

- action: "file:write"
path: "/tmp/**"
effect: allow

- action: "network:request"
host: "*.blob.core.windows.net"
method: "GET"
effect: allow

- action: "network:request"
host: "*.blob.core.windows.net"
method: "PUT"
effect: deny
reason: "Agent is read-only for Blob Storage"

- action: "network:request"
host: "169.254.169.254"
effect: deny
reason: "Block Azure IMDS credential harvesting"

- action: "env:read"
key: "AZURE_CLIENT_SECRET"
effect: deny
reason: "Agent must not read service principal secrets"

- action: "shell:execute"
command: "az *"
effect: deny
reason: "Direct Azure CLI usage blocked"

Step 3 — Deploy on Azure App Service

In your deployment pipeline, ensure SafeClaw is initialized before the agent starts:

# In your build step
npm ci --production
npx @authensor/safeclaw

Configure your web.config or startup command:

node agent.js

Assign a managed identity to the App Service and scope its RBAC roles to specific resource groups. SafeClaw gates the agent's actions at the application level, while managed identity gates access to Azure APIs.

Step 4 — Deploy on Azure Container Apps

FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
RUN npx @authensor/safeclaw
CMD ["node", "agent.js"]

Deploy with a system-assigned managed identity:

az containerapp create \
  --name ai-agent \
  --resource-group agent-rg \
  --image myregistry.azurecr.io/ai-agent:latest \
  --system-assigned \
  --env-vars SAFECLAW_AUDIT_SINK=stdout

Container Apps auto-scales, so SafeClaw's stateless policy evaluation works across all replicas. The hash-chained audit log streams to Azure Log Analytics through stdout.

Step 5 — Deploy on AKS

Mount the SafeClaw policy as a Kubernetes ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: safeclaw-policy
data:
  safeclaw.config.yaml: |
    version: 1
    defaultAction: deny
    rules:
      - action: "file:read"
        path: "/app/**"
        effect: allow
      - action: "network:request"
        host: "*.blob.core.windows.net"
        method: "GET"
        effect: allow

Use Azure Workload Identity to bind a scoped managed identity to the Kubernetes service account running your agent pod.

Step 6 — Deploy on Azure Functions

import { createSafeClawGate } from "@authensor/safeclaw";

const gate = createSafeClawGate({ policy: "./safeclaw.config.yaml" });

export default async function (context, req) {
const agent = buildAgent({ gate });
const result = await agent.run(req.body);
context.res = { body: result };
}

Azure Functions log stdout to Application Insights automatically, capturing SafeClaw's audit trail.

Step 7 — Block IMDS Credential Harvesting

Azure's Instance Metadata Service (IMDS) at 169.254.169.254 exposes managed identity tokens. An unrestrained AI agent could exfiltrate these tokens via network requests. SafeClaw blocks this at the application layer:

rules:
  - action: "network:request"
    host: "169.254.169.254"
    effect: deny
    reason: "IMDS access blocked — agent must not harvest identity tokens"

This is defense-in-depth that complements network security groups.

Step 8 — Verify Audit Integrity

npx @authensor/safeclaw audit verify --last 100

Every action is recorded in a tamper-proof hash chain. Export to Azure Blob Storage for compliance archival.


Related Pages

Try SafeClaw

Action-level gating for AI agents. Set it up in your browser in 60 seconds.

$ npx @authensor/safeclaw