Actions Run Past Sharing Unless You Say So
Module 4 of 6 in the chapter Beyond the Record: Agents, chapter 20 of Securing Salesforce: Sharing and Visibility. Each module stands on its own.
The question this module answers: An agent runs as a user, but it does its work through actions. When does an action read more than that user can see?
An agent works through its actions
Section titled “An agent works through its actions”An agent doesn’t open records the way a person does. It does its work through actions: flows, Apex and prompt templates. Salesforce’s agent user page lists exactly those three: the agent user needs object permissions “for each object that the agent interacts with via flows, Apex, or prompt templates” (Configure Service Agent Access (opens in a new tab), Salesforce Help, checked 2026-11-26).
Salesforce also tells you to keep that list short: “You can (and should) limit an agent to only execute pre-defined, approved actions, such as specific Salesforce Flows, Apex classes, or API calls” (Agentforce Security and the Shared Responsibility Model (opens in a new tab), Salesforce Help knowledge article 005315874, published 2026-02-25, checked 2026-11-26).
Here’s why the list matters for sharing. Modules 1 to 3 set up the agent’s user. But an action is code, and chapter 17 taught you that code decides who sees what. Each action has a run context of its own. It can stay inside the agent user’s access, or it can read straight past it. The agent will repeat whatever the action hands back.
So every action is an entry point, and every entry point gets the same question: whose access does this read with?
Flows: two contexts apply
Section titled “Flows: two contexts apply”For flows, Salesforce says it directly: “When an agent action runs a flow, both the flow’s run context and the agent’s execution context apply” (Agent Execution Context and Data Access by Type (opens in a new tab), Salesforce Help, checked 2026-11-26). Its table, on the same page:
| The flow’s run context | Object and field access | Records |
|---|---|---|
| User | The running user’s permissions and field-level access | The running user’s sharing |
| System context with sharing | All objects and fields | The running user’s sharing |
| System context without sharing | All objects and fields | All records |
And a note to remember for service agents: when one runs as its agent user, “the running user of the flow is the agent user (EinsteinServiceAgent User), not the customer or end user” (same page). So a flow in user context limits the agent to the agent user’s access, which you designed in module 2. A flow in system context without sharing ignores it.
Chapter 17 module 6 covers the four run options in full. For agents, one stands out: User Context—Enforces User Permissions, new in Winter ‘27 at API version 68.0. A flow set that way “always runs with the running user’s access level, even if its caller runs in system context.” For a flow built as an agent action, start there. Elevate only the one step that needs it, in a subflow that returns an answer.
Apex: the keyword and the mode
Section titled “Apex: the keyword and the mode”An Apex action is a class the agent calls, and two settings decide what it reads (chapter 17 modules 1 to 3):
- The sharing keyword decides which records:
with sharing,without sharingorinherited sharing. Give every class an agent calls an explicit keyword. Never leave it to the default (chapter 17 module 2). - The mode decides which objects and fields: user mode checks them, system mode doesn’t. Query in user mode unless you can write down why not (chapter 17 module 3).
If an action truly must see past the user, say to check whether any appointment is free across every region, make it a narrow elevation: the method looks with full access and returns an answer, yes or no, a count, a date. Never the records. An agent will happily put into words every record a without sharing method hands back.
Prompt templates: grounding as the user
Section titled “Prompt templates: grounding as the user”A prompt template pulls Salesforce data into the prompt, which is called grounding. Salesforce says the Einstein Trust Layer does “secure data retrieval of Salesforce data for grounding the prompt based on the permissions of the user executing the prompt,” and that it “preserves in place all standard Salesforce role-based controls for user permissions and field-level security when merging grounding data from your CRM instance or Data 360” (Einstein Trust Layer (opens in a new tab), Salesforce Help, checked 2026-11-26).
That’s good news, and it has one limit. A template can also ground with a flow or Apex. Then that flow’s or class’s run context comes with it, so everything in the two sections above applies to the template too.
The gap to look for
Section titled “The gap to look for”Put the three together, and the review question for every agent is short. Find the action that reads past its user.
| The action | Stays inside the user’s access | Reads past it |
|---|---|---|
| Flow | User Context—Enforces User Permissions; user context | System context without sharing; system context with sharing for fields |
| Apex | with sharing, user mode | without sharing, system mode, no keyword |
| Prompt template | Record merge fields, grounded as the user | Grounding through a system-context flow or a without sharing class |
Then keep an inventory: every action each agent can call, its run context, and, for every one that reads past its user, a sentence on why. It’s chapter 17 module 7’s system-mode inventory, with one more column: which agents call it.
Test knowledge. Know that Apex runs in system mode by default; that
with sharing,without sharingandinherited sharingdecide which records a class sees; that user mode enforces object permissions and field-level security; and that flows run in user context or system context, with or without sharing, depending on how they start and how they’re set. For agents, beyond the exam: an agent action’s run context decides what the agent can read, whoever the agent runs as. A likely area, not a known question.
What an architect decides here
Section titled “What an architect decides here”- The approved actions for each agent, and nothing else.
- Each action’s run context: flows in User Context—Enforces User Permissions where they can be, Apex with an explicit keyword and user mode.
- For every action that must read past its user, a narrow elevation that returns an answer, and a written reason.
- How prompt templates ground: record merge fields as the user, and which flows or classes they call.
- An inventory of every action, its context, and which agents call it, kept with the system-mode inventory.
Beyond the exam: what AI changes. Code always decided who sees what. What’s new is that an agent turns whatever code returns into a fluent answer, at once, to whoever asked. A leak that used to need a person to notice a field on a screen now arrives as a sentence.
Explore
Section titled “Explore”- Agent Execution Context and Data Access by Type (opens in a new tab), Salesforce Help (checked 2026-11-26)
- Agentforce Security and the Shared Responsibility Model (opens in a new tab), Salesforce Help knowledge article (checked 2026-11-26)
- Einstein Trust Layer (opens in a new tab), Salesforce Help (checked 2026-11-26)
- For the mechanics: Sharing When Writing Apex: Secure Code, chapter 17
- Configure Service Agent Access (opens in a new tab), Salesforce Help (checked 2026-11-26)
