Skip to content

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.

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.

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.

Terminal window
npm install @vulnify/sdk
import { 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 person
console.log(await exportTool('Customer Database', 800, 'partner@example.com')); // BLOCK: customer PII stays in

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/v1
kind: Policy
metadata:
name: review-external-internal-exports
spec:
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/v1
kind: Policy
metadata:
name: block-bulk-external-exports
spec:
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/v1
kind: Policy
metadata:
name: block-external-sensitive-exports
spec:
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/v1
kind: Policy
metadata:
name: review-external-customer-email
spec:
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: ENFORCE

Inside 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:

Terminal window
npx -p @vulnify/sdk vulnify policies validate
npx -p @vulnify/sdk vulnify policies apply --dry-run
npx -p @vulnify/sdk vulnify policies apply

apply 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.

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.