Ship agent actions safely: a checklist
Work through the controls an agent that writes to real accounts needs before launch, from credentials and per-user limits to approvals, retries, unknown outcomes and the halt switch, with the code for each.
An agent that only reads can be wrong. An agent that writes can be wrong in someone’s inbox, CRM or Stripe balance, and a prompt injection or a retry loop turns one bad call into hundreds. Each control below closes one of those gaps, and each is a few lines because Anlyon enforces it on every call: you do not build the token store, the counter, the approval backend or the reconciliation job.
Work through the list in a test environment first. Each item says what it prevents, what to do, and how to check it.
The examples use two keys. An operator key defines actions, limits and policies. An app key with actions:invoke and actions:read is what your running app holds; to act for your users it also holds end-users:write and end-users:approvals. See API keys and scopes.
1. Keep credentials out of the agent
Prevents: a leaked prompt, log or tool trace exposing a provider key, and an injected instruction sending that key somewhere else.
Put each provider call behind an action. The credential is a reference in the action’s header, {{secret:NAME}} for your own key or {{connection:<integration>}} for the account of the user the call is for. Anlyon adds it at dispatch, only to the hosts it is bound to. Then remove every provider key from the agent’s environment.
await ops.actions.create({
name: 'open-issue',
method: 'POST',
urlTemplate: 'https://api.github.com/repos/acme/support/issues',
headers: { Authorization: 'Bearer {{connection:github}}', Accept: 'application/vnd.github+json', 'User-Agent': 'acme' },
bodyTemplate: { title: '{{input.title}}', body: '{{input.body}}' },
inputSchema: { type: 'object', required: ['title', 'body'], properties: { title: { type: 'string' }, body: { type: 'string' } } },
impact: { dimension: 'issues', amount: '1', bound: 'exact' },
});curl -s -X POST https://api.anlyon.com/api/v2/actions \
-H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "open-issue", "method": "POST", "urlTemplate": "https://api.github.com/repos/acme/support/issues",
"headers": { "Authorization": "Bearer {{connection:github}}", "Accept": "application/vnd.github+json", "User-Agent": "acme" },
"bodyTemplate": { "title": "{{input.title}}", "body": "{{input.body}}" },
"inputSchema": { "type": "object", "required": ["title", "body"], "properties": { "title": { "type": "string" }, "body": { "type": "string" } } },
"impact": { "dimension": "issues", "amount": "1", "bound": "exact" } }'ops.actions.create(
name="open-issue",
method="POST",
url_template="https://api.github.com/repos/acme/support/issues",
headers={"Authorization": "Bearer {{connection:github}}", "Accept": "application/vnd.github+json", "User-Agent": "acme"},
body_template={"title": "{{input.title}}", "body": "{{input.body}}"},
input_schema={"type": "object", "required": ["title", "body"], "properties": {"title": {"type": "string"}, "body": {"type": "string"}}},
impact={"dimension": "issues", "amount": "1", "bound": "exact"},
)Check: the agent’s process has no provider key, and an action that points a credential at another host is refused when saved. The agent still holds an Anlyon key, so it can call any action that key may call: give it only actions:invoke and actions:read. See Secrets and Govern any HTTP API.
2. Name the user on your server, never in the model
Prevents: a model, or an injected instruction, choosing whose account a call acts in.
Your server builds a client bound to the signed-in user and hands it to the agent’s tools. Tool schemas have no user field. Create the app key with Require an end user (endUserRequired: true) so a call that names no user is refused instead of falling back to your company’s accounts.
const anlyon = new Client({ apiKey: process.env.ANLYON_APP_KEY! });
// session.user.id comes from your own session.
const user = anlyon.forUser(session.user.id);
const { data } = await user.actions.invoke('open-issue', { title: 'Export fails', body: 'Reported in chat.' });curl -s -X POST https://api.anlyon.com/api/v2/actions/open-issue/invoke \
-H "Authorization: Bearer $ANLYON_APP_KEY" \
-H "Anlyon-End-User: user_123" \
-H "Content-Type: application/json" \
-d '{ "input": { "title": "Export fails", "body": "Reported in chat." } }'anlyon = Client(api_key=os.environ["ANLYON_APP_KEY"])
user = anlyon.for_user(session_user_id)
result = user.actions.invoke("open-issue", {"title": "Export fails", "body": "Reported in chat."})Check: a call with the app key and no Anlyon-End-User answers 400 END_USER_REQUIRED. A user who has not connected gets 409 END_USER_NOT_CONNECTED with a connectUrl, and nothing is sent. See Act for your users.
3. Cap what the agent can change
Prevents: a loop or an injected instruction sending 500 emails, opening 200 issues or refunding a day’s revenue.
Declare what one call changes (impact), then set a limit in that unit. scope: "end_user" gives each of your users their own allowance. The amount is reserved before dispatch, so a call over the limit never reaches the provider.
await ops.impactLimits.create({
name: 'Issues per user per day',
dimension: 'issues',
period: 'day',
amount: 5,
actionName: 'open-issue',
scope: 'end_user',
});curl -s -X POST https://api.anlyon.com/api/v2/impact-limits \
-H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Issues per user per day", "dimension": "issues", "period": "day", "amount": 5, "actionName": "open-issue", "scope": "end_user" }'ops.impact_limits.create(
name="Issues per user per day",
dimension="issues",
period="day",
amount=5,
action_name="open-issue",
scope="end_user",
)Check: the call over the limit comes back 200 with status: "failed", grade: "refused" and impact_limit_exceeded in error. Read status and grade, not the HTTP status. Creating a limit needs impact-limits:write, which no key gets by default. See Impact limits and When the limit is hit.
4. Put risky writes behind an approval
Prevents: an irreversible write going out because the model was confident.
An approval policy parks a matching call until someone decides. decidedBy: "end_user" sends it to the user the call acts for, through your app. decidedBy: "team" (the default) sends it to your team’s inbox and Slack. A condition narrows it, for example to large amounts.
await ops.approvalPolicies.create({
name: 'The user approves each issue',
matchKind: 'action',
matchActionName: 'open-issue',
effect: 'require_approval',
decidedBy: 'end_user',
});curl -s -X POST https://api.anlyon.com/api/v2/approval-policies \
-H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "The user approves each issue", "matchKind": "action", "matchActionName": "open-issue", "effect": "require_approval", "decidedBy": "end_user" }'ops.approval_policies.create(
name="The user approves each issue",
match_kind="action",
match_action_name="open-issue",
effect="require_approval",
decided_by="end_user",
)Check: the call answers status: "pending_approval" with an approvalId, and nothing reaches the provider until approval. A denied call ends denied. An undecided one expires after the approval window, 24 hours by default. See Approvals and the quickstart.
5. Make sure what was approved is what runs
Prevents: a reviewer approving one request and a different one being sent.
Every governed call has a preview: the normalized request, its target and the action version, hashed into a bindingDigest. The approval stores that digest, and dispatch refuses on any difference. To show a reviewer the request before the agent sends it, create the preview yourself and invoke with its previewId. A different input then answers 409 PREVIEW_MISMATCH and creates nothing.
Check: change one input field between preview and invoke and confirm the 409. See Previews and When approval expires or changes. To keep the action itself from changing under an approval, pin versions with promotion.
6. Make retries safe
Prevents: a timeout followed by a retry doing the write twice.
Give every invoke an Idempotency-Key derived from the operation, such as refund:ord_4417. A repeat with the same key and request is answered from the recorded invocation, and nothing is sent again. The SDKs generate a key per invoke call when you pass none.
await user.actions.invoke('open-issue', input, { idempotencyKey: `issue:${ticketId}` });curl -s -X POST https://api.anlyon.com/api/v2/actions/open-issue/invoke \
-H "Authorization: Bearer $ANLYON_APP_KEY" \
-H "Anlyon-End-User: user_123" \
-H "Idempotency-Key: issue:T-4417" \
-H "Content-Type: application/json" \
-d '{ "input": { "title": "Export fails", "body": "Reported in chat." } }'user.actions.invoke("open-issue", payload, idempotency_key=f"issue:{ticket_id}")Check: send the same request twice. The second answer carries X-Idempotent-Replay: current-state. The same key with a different request answers 409 idempotency_key_reuse. See Idempotency and retries.
7. Treat a lost response as unknown, not failed
Prevents: an agent retrying a write that may already have landed.
When Anlyon cannot confirm the result, the outcome is unknown and the receipt grade is unknown. The write is not sent again, the allowance stays held, and a read-back settles it when the provider shows it. Tell the model in plain words to stop and keep the effectId. A verify rule on a declared action is what lets that read-back confirm the write.
Check: rehearse it with the Stripe adapter’s fault drill, which sends a test-mode refund and discards the answer. See Refund safely when the agent retries and When the outcome is unknown.
8. Know how to stop everything
Prevents: a runaway agent continuing while you investigate.
The halt switch stops new external calls in one environment at once. Calls already sent to a provider are not recalled. A key with environments:halt, which no key gets by default, can pull it from a script. In the console any member can halt, and only an admin can resume.
const oncall = new Client({ apiKey: process.env.ANLYON_ONCALL_KEY! });
await oncall.environment.halt({ reason: 'runaway refund loop' });
// later
await oncall.environment.resume();curl -s -X POST https://api.anlyon.com/api/v2/environment/halt \
-H "Authorization: Bearer $ANLYON_ONCALL_KEY" \
-H "Content-Type: application/json" \
-d '{ "reason": "runaway refund loop" }'oncall = Client(api_key=os.environ["ANLYON_ONCALL_KEY"])
oncall.environment.halt(reason="runaway refund loop")Check: while halted, an invoke answers 409 ENVIRONMENT_HALTED and nothing is sent. Reconciling an unknown outcome still works. See Environments.
9. Keep staging away from production
Prevents: a test run writing to production accounts.
A key belongs to one environment, and actions, secrets, connections, limits and policies are scoped to it. A staging key cannot reach production’s actions or halt production. Connect test accounts to staging: Anlyon keeps environments apart, but cannot separate one provider account you connect to both.
Check: call a production-only action with a staging key and confirm it is not found. See Environments.
10. Rehearse the failure paths
A successful run only proves the path that ran. Before launch, run each of these in a non-production environment and check the stored invocation or effect, not only the response the agent received.
| Drill | Expect |
|---|---|
| Deny an approval | Invocation denied, grade denied, nothing sent. |
| Let an approval expire | The call never runs. |
Invoke with a used or expired previewId |
409 PREVIEW_ALREADY_USED or 409 PREVIEW_EXPIRED. |
| Exhaust a limit | status: "failed", grade refused, impact_limit_exceeded. |
| Call for a user who has not connected | 409 END_USER_NOT_CONNECTED with a connectUrl. |
| Call with the app key and no user | 400 END_USER_REQUIRED. |
| Repeat an invoke with the same key | Answered from the record, X-Idempotent-Replay: current-state. |
| Lose a response (fault drill) | Grade unknown, then confirmed once the read-back finds it. |
| Halt the environment, then invoke | 409 ENVIRONMENT_HALTED. |
| Use a key without a scope | 403 AUTHORIZATION_ERROR naming the scope. |
Anlyon’s controls make each call bounded, approved and recorded. They do not detect prompt injection, and an allowed action can still be misused within its limits. Keep each action narrow: fixed hosts, a strict input schema and the smallest allowance that works. For oversight reviews, see Compliance and Audit.
Quickstart
One governed action for one user, with their approval and a per-user limit.
Act for your users
The whole app: connections, approvals in your UI, per-user limits.
Govern any HTTP API
Declare impact and read-backs on any HTTPS API.
Receipts and grades
What each grade means and how to read the evidence.

