<!-- Canonical HTML: https://docs.didro.ai/sap-ui-automation/concepts/safety -->

# Safety model

What stops an agent from saving something wrong in SAP? First, your SAP
authorisations and the system you point it at: a test system is the normal
place to let it write, and for read-only work on production the real answer
is an SAP user with display authorisations only. On top of that, settings
can make the server read-only or limit it to some systems and transactions.
The server enforces these rules whatever the agent decides. They are a
safety net for an agent that makes mistakes, not a security boundary: see
[Security and data handling](https://docs.didro.ai/sap-ui-automation/security) for what they do not protect
against.

The server works in your own sessions, as you, under your SAP
authorisations. It never logs on and never stores a password. Password
fields cannot be typed into, and nothing runs on a logon screen: log on
yourself. (With the Chrome extension, the extension can log on to a system
you registered, with a password it keeps; the server never sees it.)

## Settings

| Setting | Effect |
| --- | --- |
| `SAP_WRITE=on` (default) | actions that may write (Save, Post, Delete, Release, Approve, "Yes" on a save popup) run. Your MCP client's tool approval is the only question before them ([below](#approval-in-the-client)) |
| `SAP_WRITE=off` | read-only: every such action is refused. Navigation, display transactions, reports, filling fields and value help still run |
| `SAP_ALLOW_SYSTEMS=ABA/800,S4H` | only these systems, optionally with a client, are visible and usable. Checked on every tool, each time: a session that moves to another system is refused from then on |
| `SAP_ALLOW_ORIGINS=https://myhost:44300` | only browser tabs of these origins are looked at |
| `SAP_ALLOW_TCODES=VA03,MM03` | the agent may open and work in only these transactions |
| `SAP_BLOCK_TCODES=SE38,SM30` | the agent may not open or work in these transactions |
| `SAP_ALLOW_LOGOFF=on` | the agent may end SAP sessions or the logon (`/nex`, `/nend`, `/i`, Log Off, Yes on the Log Off popup). Off by default, also with `SAP_WRITE=on`: logging off drops the unsaved work of every session, and only you can log on again |

Lists are separated by commas (or spaces) and are not case-sensitive. A
value of `SAP_WRITE` or `SAP_ALLOW_LOGOFF` the server does not know stops
it at start. Every setting: [Configuration](https://docs.didro.ai/sap-ui-automation/reference/configuration).

## Approval in the client

With `SAP_WRITE=on` the server asks nothing itself. `sap_act`, `sap_replay`
and `sap_workflow_run` are marked destructive (`destructiveHint`), so a
client that asks before each destructive call (Codex) asks before each of
them. Under `off` they are not, unless `SAP_ALLOW_LOGOFF=on`. That approval
covers every call, not only the ones that write.

- **Claude Code:** leave `mcp__sap-ui-automation__sap_act` (as the plugin:
  `mcp__plugin_sap-ui-automation_sap-ui-automation__sap_act`) out of
  `permissions.allow`, or put it in `ask`.
- **Codex:** set `approval_mode = "prompt"` for that tool. In Full Access
  mode Codex asks nothing.

## Systems

With `SAP_ALLOW_SYSTEMS` set, a session is visible only when its system
(and, when the entry names one, its client) is in the list: `ABA` allows
every client of ABA, `ABA/800` only client 800. Sessions of other systems
are hidden from `sap_sessions`, which says how many were hidden, and every
tool refuses them. A session whose system the server cannot read passes
only when no list is set.

For browser tabs, `SAP_ALLOW_ORIGINS` narrows what is looked at before any
of this: tabs of other origins are not read at all.

## Transactions

The transaction lists apply to commands (`/nSE38`, `/oSE38`, `/*SE38`, or
`SE38` alone) and to the transaction the session is in. A menu entry, a
favourite or a double-click in a tree can open a transaction without a
command: the server reads the transaction before and after each action. If
an action of `sap_act` lands in a transaction the lists refuse, the server
says so and leaves it with `/n`. A replay judges each step by the same
lists; when a replay fails, `sap_replay` stays on the failing screen so
that the agent can look, and `sap-ui-automation replay` leaves the
transaction with `/n` unless `--stay` (not on Fiori). If the session is already in one, only a command that
leaves it is accepted. With `SAP_ALLOW_TCODES` set, a session may still sit
on the start screens (`SESSION_MANAGER`, `SMEN`, `S000`, the launchpad
home).

`/nex`, `/nend` and `/i` close sessions; they are not transactions, and
`SAP_ALLOW_LOGOFF` decides on them.

On Fiori the "transaction" is the app's intent (such as
`SalesOrder-display`), and the lists compare against that. When `open`
starts a Web GUI transaction through `#Shell-startGUI?sap-ui2-tcode=...`,
the lists also check the decoded transaction code (an allow list must allow
both `Shell-startGUI` and the transaction). Once a Web GUI app is already
open inside the launchpad, its inner screen transaction is not reported to
the lists separately.

## The command field

The command field (`okcd`) takes commands through `{"do":"okcode"}` only.
`set`, `focus` or any other action on the field itself is refused, on every
surface, so that a command cannot go round the guard: typing `/11` or
`=SAVE` there and pressing Enter would pass none of the rules above.

## What counts as a write

Each surface classifies an action before it runs:

- **read:** value help, expanding a tree node, scrolling a list, listing a
  dropdown's entries;
- **navigate:** typing, Enter, tabs, Back, Execute (F8);
- **commit:** anything that may save, and anything not known to be safe.

Only commits are subject to `SAP_WRITE`.

The rule fails closed. A button, menu entry, function key or function code
is a commit unless it is known to be safe:

- by its key: Enter, Back, Cancel, F4, paging... (a toolbar button `btn[N]`
  is function key N);
- by its function code, such as the standard functions of ALV grids (sort,
  filter, find, details) and choosing or changing a classic list's layout
  (saving or deleting a layout stays a commit);
- by its menu, on Web GUI: entries under a list's Settings > Layout, and
  further selection criteria or dynamic selections;
- by its text, when the logon language is one the word lists cover;
- by its place, on Web GUI: the Goto menu, value help, a message popup, a
  report's selection screen, a screen that only displays (below).

A text that holds a commit word is a commit even when the rest of it is
safe ("Save and back"). A popup that asks whether to save, post or
delete makes every answer but No and Cancel a commit; the Enter button of
a popup that only informs just acknowledges it. Enter or Space on a focused
button counts as pressing that button. Typing works only in fields, never
on buttons.

Ending sessions or the logon (`/nex`, `/nend`, `/i`, Log Off, Yes on the
Log Off popup) is judged on its own, because it closes sessions and drops
unsaved data: it is refused unless `SAP_ALLOW_LOGOFF=on`, whatever
`SAP_WRITE` says, and runs when it is on. To leave a transaction, the agent
uses `/n`.

### Safe and commit words

Commit words (save, post, delete, release, approve...) are known in
English, German, French, Spanish, Portuguese, Italian and Dutch. Safe words
(Display, Find, Refresh, Next, Back...) are known in English, German,
French and Spanish. In another logon language, only ids, keys and function
codes count as safe, so more actions count as writes. The lists are in
[`src/core/words.ts`](https://github.com/DidroAI/sap-ui-mcp/blob/main/src/core/words.ts),
one table for all surfaces.

### The cost of failing closed

Some harmless buttons count as commits too (for example "Continue" on a
popup whose text the server does not know as safe): with `SAP_WRITE=off`
they are refused. The agent is told why, and can tell you.

### A screen that only displays (Web GUI)

When the title of the main window says "Display ..." and the system toolbar
has no Save, the transaction's own buttons and menu entries count as
navigate (item conditions, schedule lines, a list of orders). SAP offers no
way to save there. Still commits: anything named with a commit word, functions
that act beyond the screen (print, issue output, start, execute...), the
System and Help menus, and the toolbar buttons of grids and trees.

### Execute (F8)

Execute counts as navigate on purpose. It runs reports and lists (VA05,
ME2N...), which read. In Web GUI, Execute on a selection screen is a commit
when the screen shows that the report updates: a "Test Run" box that is not
ticked (tick it, and the report runs without writing), an "Update Run"
choice that is selected, or a title that names what the report does and not
a list ("Deletion of Jobs", "Batch Input: Process All Sessions"). A report
that updates without any of these signs still runs: put known update
programs in `SAP_BLOCK_TCODES`.

### Fiori

On Fiori the same rule reads a control's id (Fiori elements gives its
standard actions stable ids, such as Save, Create, Delete, Edit, Cancel),
its text, its press handlers and where it sits. An OData action behind a
button is a commit. In a draft-enabled app, typing into a field saves the
draft on the server at once: that is not counted as a commit; activating
the draft (Save, Create) is. Opening an app is navigation; an intent that
carries a function code for a transaction (`DYNP_OKCODE`) counts as a
write.

## A write goes only to the screen the agent saw

Before an action that may write runs, the server compares SAP's screen with
the last one it showed the agent: transaction, program, screen number and
popups. When SAP has moved on (a late answer, a popup, another program
acting on the session), the write does not run, and the answer is the
screen SAP is on now:

```
Not run: it may write, and SAP is not on the screen you last saw: it is now ZA01, program SAPMZA01, screen 100. Read the screen below; send the action again only if it is still what you want here
```

Sent again after that, it runs, because the agent has now seen that
screen. The same rule holds for the first write of a batch; the later
writes of a batch follow the batch's own rule ([Several actions in one
call](https://docs.didro.ai/sap-ui-automation/reference/tools#several-actions-in-one-call)). Before any
screen was shown there is nothing to compare, and the write runs.

## After a write that did not run

A write that did not run leaves the transaction as the agent left it,
often with a document open for change, and SAP keeps that document locked
for everyone else. Tell the user about the edits and the lock. Leaving with
`/n` or choosing SAP's discard answer can lose earlier work on the same
screen. Discard only disposable input you entered on a clean screen or
edits the user authorized you to discard.

## What it does not catch

This is a safety net, not a guarantee. A custom button whose name is on the
safe list can still write, and so can a report started with F8 that shows
no sign of updating. Use a test system and a user with the authorisations
you want the agent to have.
