Stop an AI agent from exporting customer data
An agent that can export records or send email can send customer data to the wrong place. A prompt injection in a ticket asks for “a copy of the customer list”. A sales agent attaches a full export when one row was enough. The data leaves before anyone looks. That is data exfiltration, even when nobody intended it.
Most of what the agent does is fine and should not wait for anyone. The risk is concentrated in a few actions: exports, and email to addresses outside the company.
This guide checks those actions before they run. An export of internal data to an outside address waits for a person to approve it. Customer PII and other sensitive data never go out: an export of them to an outside destination is blocked as CRITICAL, at any record count. A bulk external export is blocked. Email outside the company domain waits for approval. Internal email keeps running.
How it works
Section titled “How it works”Before the export or the email, your code asks Vulnify about the action: the agent, EXPORT_DATA or SEND_EMAIL, the resource, the destination, and the record count. Vulnify answers ALLOW, REVIEW, or BLOCK. The action runs only when finalDecision is ALLOW. See Decisions.
destination is INTERNAL when the address is on your company domain and EXTERNAL_EMAIL otherwise. Use EXTERNAL_API when the data goes to another service. See Actions.
You need an API key from app.vulnify.io. Use a TEST key while you try this. Register the agent (SalesBot) and the resources in the app under those names, or change the names in the code. The resource type decides the outcome, so set it:
Sales Reports, type Internal. External exports of it go to a person.Customer Database, type Customer PII. External exports of it are blocked.Customer Contacts, the address book the email tool reads.
1. Guard the export and the email
Section titled “1. Guard the export and the email”The export tool waits up to 2 minutes for a person to approve a REVIEW, then runs only if it was approved. The email tool does not wait: a REVIEW stops the send and the model is told a person must approve. content is optional. Vulnify scans it for sensitive data and does not store it.
npm install @vulnify/sdkimport { Vulnify, VulnifyBlockedError } from '@vulnify/sdk';
const apiKey = process.env.VULNIFY_API_KEY;if (!apiKey) { throw new Error('Set VULNIFY_API_KEY');}
const vulnify = new Vulnify({ apiKey, baseUrl: process.env.VULNIFY_BASE_URL });
const COMPANY_DOMAIN = '@yourcompany.com';
function destinationFor(address: string): 'INTERNAL' | 'EXTERNAL_EMAIL' { return address.toLowerCase().endsWith(COMPANY_DOMAIN) ? 'INTERNAL' : 'EXTERNAL_EMAIL';}
/** Replace the bodies with your real export and email calls. */async function exportData(resource: string, rows: number, to: string): Promise<void> { console.log(`exporting ${rows} records from ${resource} to ${to}`);}async function sendEmail(to: string, subject: string, body: string): Promise<void> { console.log(`sending "${subject}" to ${to} (${body.length} chars)`);}
/** Export tool: on REVIEW, wait up to 2 minutes for a person to approve (in the app or in Slack). */async function exportTool(resource: string, rows: number, to: string): Promise<string> { try { await vulnify.guard( { agent: 'SalesBot', action: 'EXPORT_DATA', resource, destination: destinationFor(to), recordsAffected: rows, }, () => exportData(resource, rows, to), { timeoutMs: 120_000, pollMs: 2000 }, ); return `Exported ${rows} records from ${resource} to ${to}.`; } catch (error) { if (error instanceof VulnifyBlockedError) { // BLOCK, or a review that was denied, expired, or not answered in time. return `Export not run. ${error.message} (event ${error.result.id ?? 'none'})`; } throw error; }}
/** Email tool: no wait. REVIEW stops the send and tells the model a person must approve. */async function emailCustomerTool(to: string, subject: string, body: string): Promise<string> { try { await vulnify.guard( { agent: 'SalesBot', action: 'SEND_EMAIL', resource: 'Customer Contacts', destination: destinationFor(to), recordsAffected: 1, content: body, // optional: scanned for sensitive data, not stored }, () => sendEmail(to, subject, body), ); return `Email sent to ${to}.`; } catch (error) { if (error instanceof VulnifyBlockedError) { return `Email not sent. ${error.message} (event ${error.result.id ?? 'none'})`; } throw error; }}
console.log(await emailCustomerTool('ana@example.com', 'Your renewal', 'Hi Ana, your plan renews next week.'));console.log(await exportTool('Sales Reports', 800, 'partner@example.com')); // REVIEW: waits for a personconsole.log(await exportTool('Customer Database', 800, 'partner@example.com')); // BLOCK: customer PII stays inpip install vulnifyimport os
from vulnify import Vulnify, VulnifyBlockedError
api_key = os.environ.get("VULNIFY_API_KEY")if not api_key: raise SystemExit("Set VULNIFY_API_KEY")
vulnify = Vulnify(api_key=api_key)
COMPANY_DOMAIN = "@yourcompany.com"
def destination_for(address: str) -> str: return "INTERNAL" if address.lower().endswith(COMPANY_DOMAIN) else "EXTERNAL_EMAIL"
def export_data(resource: str, rows: int, to: str) -> None: """Replace with your real export. It runs only after ALLOW or an approval.""" print(f"exporting {rows} records from {resource} to {to}")
def send_email(to: str, subject: str, body: str) -> None: """Replace with your real email call. It runs only after ALLOW.""" print(f'sending "{subject}" to {to} ({len(body)} chars)')
def export_tool(resource: str, rows: int, to: str) -> str: """On REVIEW, wait up to 2 minutes for a person to approve (in the app or in Slack).""" try: vulnify.guard( lambda: export_data(resource, rows, to), wait={"timeout": 120, "poll": 2}, agent="SalesBot", action="EXPORT_DATA", resource=resource, destination=destination_for(to), records_affected=rows, ) return f"Exported {rows} records from {resource} to {to}." except VulnifyBlockedError as blocked: # BLOCK, or a review that was denied, expired, or not answered in time. return f"Export not run. {blocked} (event {blocked.result.id or 'none'})"
def email_customer_tool(to: str, subject: str, body: str) -> str: """No wait: REVIEW stops the send and tells the model a person must approve.""" try: vulnify.guard( lambda: send_email(to, subject, body), agent="SalesBot", action="SEND_EMAIL", resource="Customer Contacts", destination=destination_for(to), records_affected=1, content=body, # optional: scanned for sensitive data, not stored ) return f"Email sent to {to}." except VulnifyBlockedError as blocked: return f"Email not sent. {blocked} (event {blocked.result.id or 'none'})"
print(email_customer_tool("ana@example.com", "Your renewal", "Hi Ana, your plan renews next week."))print(export_tool("Sales Reports", 800, "partner@example.com")) # REVIEW: waits for a personprint(export_tool("Customer Database", 800, "partner@example.com")) # BLOCK: customer PII stays inFrom Claude, Cursor, Grok, or any MCP client connected to the Vulnify MCP server, the assistant records the decision with decide_action before it exports:
{ "agent": "SalesBot", "action": "EXPORT_DATA", "resource": "Sales Reports", "destination": "EXTERNAL_EMAIL", "recordsAffected": 800}When finalDecision is REVIEW, it does not export. The same call with "resource": "Customer Database" returns BLOCK, and the export must not run at all. After a person approves, get_decision reads the result. waitMs polls for up to 30 seconds:
{ "id": "<event id from decide_action>", "waitMs": 30000 }The export may run only when get_decision returns finalDecision ALLOW. The MCP server has no approve tool. A person approves in Vulnify or in Slack.
2. Add the policy
Section titled “2. Add the policy”Four rules. They do not overlap, so only one matches a given action:
- External exports from an Internal resource, up to 1000 records, go to a person.
- External exports of more than 1000 records without sensitive data are blocked.
- External exports of sensitive data are blocked at any size. That covers resources of type Sensitive, Customer PII, Financial, or Employee, and content where Vulnify finds sensitive data.
- Email to an external address goes to a person.
resource: INTERNAL matches resources whose type is Internal. containsSensitiveData: true matches a sensitive resource type or sensitive data found in the content. SEND_EMAIL has no action family of its own, so that rule uses action: ANY and puts SEND_EMAIL in the condition. The format is on Policy files.
apiVersion: vulnify.io/v1kind: Policymetadata: name: review-external-internal-exportsspec: description: A person approves exports of internal data that leave the company, up to 1000 records enabled: true action: EXPORT resource: INTERNAL condition: destination: EXTERNAL containsSensitiveData: false maxRecords: 1000 decision: REVIEW mode: ENFORCE approverRoles: - OWNER - ADMIN---apiVersion: vulnify.io/v1kind: Policymetadata: name: block-bulk-external-exportsspec: description: Exports of more than 1000 records never leave the company enabled: true action: EXPORT resource: ANY condition: destination: EXTERNAL containsSensitiveData: false minRecords: 1001 decision: BLOCK mode: ENFORCE---apiVersion: vulnify.io/v1kind: Policymetadata: name: block-external-sensitive-exportsspec: description: Customer PII and other sensitive data never leave the company enabled: true action: EXPORT resource: ANY condition: destination: EXTERNAL containsSensitiveData: true decision: BLOCK mode: ENFORCE---apiVersion: vulnify.io/v1kind: Policymetadata: name: review-external-customer-emailspec: description: A person approves agent email to addresses outside the company enabled: true action: ANY resource: ANY condition: action: SEND_EMAIL destination: EXTERNAL decision: REVIEW mode: ENFORCEInside the company, the risk engine still sends exports of Customer PII or Sensitive data to review (HIGH, 55 for up to 100 records and 65 above). Internal exports of Internal data and internal email come back ALLOW.
Save it as vulnify/policies/exports.yaml, then check and apply it with the CLI:
npx -p @vulnify/sdk vulnify policies validatenpx -p @vulnify/sdk vulnify policies apply --dry-runnpx -p @vulnify/sdk vulnify policies applyapply needs an org-wide LIVE key. You can also create the rules in the app under Policies. Start with mode: MONITOR if you want to see what would be reviewed before you enforce it.
3. What REVIEW and BLOCK look like
Section titled “3. What REVIEW and BLOCK look like”These results come from the Vulnify decision path, the same one behind POST /v1/events, vulnify test, and POST /v1/policies/test, with the four rules above. They are not made-up values. Fields are trimmed.
An export of 800 records from Sales Reports (type Internal) to an external email address came back as REVIEW:
{ "decision": "REVIEW", "finalDecision": "REVIEW", "riskLevel": "HIGH", "riskScore": 65, "reasons": ["Export operation", "External destination", "Large data volume (800 records)", "Policy matched: review-external-internal-exports"], "policy": { "name": "review-external-internal-exports" }, "decisionSource": "policy", "dlpFindings": []}The export did not run. The Slack alert showed Approve and Deny. After Approve, get_decision returned finalDecision ALLOW, and only then could the export run. The stored decision stays REVIEW. See Reviews and Slack.
The same export of 800 records from Customer Database (type Customer PII) came back as BLOCK. Nobody is asked to approve it:
{ "decision": "BLOCK", "finalDecision": "BLOCK", "riskLevel": "CRITICAL", "riskScore": 90, "reasons": ["Export operation", "Customer PII", "External destination", "Large data volume (800 records)", "Policy matched: block-external-sensitive-exports"], "policy": { "name": "block-external-sensitive-exports" }, "decisionSource": "policy"}With no policy at all, the result is the same BLOCK, CRITICAL, 90, with policy null and decisionSource engine. If only a REVIEW rule matched, the result is still BLOCK: policy.name names the REVIEW rule for information, decisionSource is engine, and reasons ends with Engine risk CRITICAL overrides policy REVIEW. With 100 records or fewer the score is 80, still CRITICAL.
An export of 12,000 records from Customer Database to an external email address, with a TEST key and no policy, came back as BLOCK from the risk engine:
{ "decision": "BLOCK", "finalDecision": "BLOCK", "riskLevel": "CRITICAL", "riskScore": 100, "reasons": ["Export operation", "Customer PII", "External destination", "Large data volume (12,000 records)"], "policy": null, "decisionSource": "engine"}With the rules above applied, that export matches block-external-sensitive-exports and policy.name names it. An export of 12,000 records from Sales Reports matches block-bulk-external-exports and comes back BLOCK, CRITICAL, 85. The email to ana@example.com matches review-external-customer-email and comes back REVIEW. With Customer Contacts typed Customer PII, it scores HIGH, 65. Your scores and reasons depend on your resources and policies.
In the code above, the tool returns a string such as Export not run. Vulnify BLOCK: … to the model. The model can tell the user why. If Vulnify cannot be reached, the SDK fails closed by default and nothing is exported.
Next steps
Section titled “Next steps”- Run the export check end to end in the Quickstart.
- Connect Slack so approvers can answer from the alert: Slack.
- Guard deletes the same way: Stop an AI agent from deleting production data.
- Use the OpenAI Agents SDK or Vercel AI SDK adapters: Framework adapters.
- Create the policy and an API key in the Vulnify app.

