SfSkills Domains Docs GitHub

Home / agentforce / prompt-injection-defense

prompt-injection-defense

Red-team an Agentforce agent against prompt-injection and jailbreak attacks; codify adversarial test cases and guardrails, scoped to the agent boundary rather than general application-security review. NOT for the overall agent test plan (topic coverage, golden sets, regression harness) — use agentforce/agentforce-testing-strategy. NOT for keeping PII out of prompts, model calls and logs — use agentforce/agentforce-pii-redaction.

Open the skill folder on GitHub


Prompt Injection Defense

Agentforce runs on the Einstein Trust Layer, which adds secure data retrieval, system policies ("Prompt Defense protects the data from prompt injection attacks or jailbreaking"), toxicity scoring, and audit. Subagent instructions and action scopes still need explicit hardening, because data masking is disabled for agents and instructions are interpreted by an LLM. Injection attempts include: instruction override, role-reversal, system-prompt leaks, tool-use coercion, and data exfiltration via crafted record content. This skill builds a reusable adversarial test suite and maps findings to concrete guardrails.

Terminology. Agentforce topics were renamed subagents in April 2026. This skill leads with subagent. The older term still appears in metadata and API names (GenAiPlugin, topic_sequence_match), in older Help articles, and in many orgs; nothing about behaviour changed with the rename.

Adoption Signals

Pre-production review for any Agentforce agent that (a) ingests user-controlled text, (b) has write access via Invocables, or (c) is exposed to external/Experience Cloud users. Required for Service agents, Sales agents with Data Cloud grounding, and any custom channel.

Questions to Ask Before Configuring

Each question traces to a gotcha in references/gotchas.md.

QuestionWhy it mattersWhat a good answer addsWhat proper configuration adds over just doing it
"Which actions change data, send messages, or call out, and what does each one check itself?"Instructions are nondeterministic; the guide says to build sensitive rules into the action (Gotcha 1)A per-action list of server-side checksA jailbreak that wins the conversation still loses at the action
"Which user does each custom action run as, and does any use without sharing or system mode?"A custom action adheres to the permissions and sharing of the Apex class or flow it references (Gotcha 2)Run-as identity and access mode per actionThe injection blast radius equals what the user could do anyway
"Which grounded fields can an outsider write?"Web-to-case text, comments, and chat transcripts reach the prompt as context, and masking does not apply to agents (Gotchas 3, 4)A list of attacker-writable grounding fieldsHigh-risk fields are projected narrowly or excluded
"Which languages and channels will the agent face?"English-only suites miss payloads in other languages, and Trust Layer language support varies (Gotcha 5)Locales and channels to include in the suiteThe suite tests the deployed audience, not a demo
"Who runs the suite, and when?"Agent behaviour is not deterministic, so a suite that is not re-run decays (Gotcha 6)An AiEvaluationDefinition in source control and a re-run triggerEvery topic or action change gets a pass or fail
"How many instructions does each subagent carry today?"Contradicting or excessive instructions degrade performance, and visual order is not priority (Gotcha 7)A trimmed instruction set with named verification actionsFewer, stronger rules that hold under test
  1. Enumerate the attack surface: every Invocable action and flow action with its run-as identity and access mode, every grounded DMO or sObject field, and every conversational input channel.
  2. Build the adversarial test set covering the five OWASP LLM-01 families: instruction override, context leakage, tool-use coercion, exfil via output, and role impersonation, with at least two non-English renderings; store it as an AiEvaluationDefinition (references/metadata-examples.md).
  3. Run each test through Agentforce Testing Center as the run-as user and each channel user; capture verbatim responses and the topic and action sequence into a results matrix.
  4. For each failed test, apply one of four mitigations: (a) move the rule into the action and re-query under user mode, (b) add or sharpen one subagent instruction that names a verification action, (c) narrow the grounding projection, (d) remove the dangerous capability.
  5. Run python3 scripts/check_prompt_injection_defense.py --manifest-dir <project> to flag system-mode or without-sharing actions, model-asserted Boolean flags, rule-like instructions, and suite coverage gaps.
  6. Re-run the suite until all tests pass; commit it beside the agent metadata so regressions are caught on every agent change.

Key Considerations

Worked Examples (see references/examples.md and references/metadata-examples.md)

Common Gotchas (see references/gotchas.md)

Top LLM Anti-Patterns (full list in references/llm-anti-patterns.md)

Official Sources Used

Package files