ADACTION
DOCK

ACTIONDOCK FIELD NOTES

AI Agent API Security: Make the First Safe Write

Learn how to move an AI agent from read-only recommendations to one policy-checked, owner-approved API write without exposing the target credential.

Abstract orange request capsule passing through a narrow policy gate toward one API endpoint on a dark background.

AI agent API security starts with a narrow question: what is the smallest real change this agent should be allowed to propose, and which non-model controls must stand between that proposal and execution?

For a team that already has a useful internal agent, the practical next step is rarely unrestricted autonomy. It is one bounded POST, PATCH, or DELETE to a known business API, checked against deterministic policy, shown to an accountable owner, and executed with a credential the agent never receives. That is the first safe write.

This architecture does not make the agent universally safe. It controls only the write path routed through it. A browser session, native connector, or direct API key remains an alternate path unless the team removes or restricts it.

Why an API write changes the security problem

A read-only agent can still expose data or make a bad recommendation. A write-enabled agent adds a different failure mode: model output can become a real side effect in a CRM, ticketing system, internal database, or operational service.

The model does not need malicious intent to cause damage. It can misunderstand an instruction, use stale context, choose an overly broad tool, or process adversarial content from a web page or document. OWASP describes prompt injection as both a direct and indirect risk, and recommends least-privilege access, deterministic validation, and human approval for high-risk actions. Its guidance on excessive agency also recommends enforcing authorization in downstream code instead of asking an LLM to decide whether its own action is allowed.

That distinction is the foundation of secure AI agent API access:

The model may propose an action. Code and accountable people decide whether that exact action can proceed.

OpenAI makes a similar point in its guidance on designing agents to resist prompt injection: an agent exposed to untrusted input needs capability limits that reduce the downside of being misled. More intelligence can improve decisions, but it does not replace authorization.

The first safe write architecture

The useful security boundary sits between agent intent and the target API. It should keep the agent as the orchestrator while removing its ability to turn arbitrary output into an arbitrary request.

Stage Question to answer Control Evidence to keep
Intent What exact change is proposed? Structured method, path, query, and body Submitted request
Policy Is this destination and operation configured? Method and path allowlists Policy decision
Review Does the owner accept this exact version? Bound approval preview Approval or rejection
Credential How is the target API authenticated? Server-held credential Connection version, not the secret
Execution What did the gateway observe? Bounded HTTPS request Status and available response
Recovery Is the result known? Terminal job state and reconciliation path Success, failure, or unknown outcome

Each stage answers a different question. Combining them into one model prompt creates a weak boundary because the same probabilistic component proposes the operation, interprets the rules, and grants itself access.

1. Configure the destination outside the agent

The workspace owner should choose the base URL, allowed HTTP methods, allowed path prefixes, and target-system credential. The agent receives only non-secret connection metadata and a connection identifier.

Provider-side permissions still matter. If the target API can issue a key scoped to one service, tenant, or operation, use that narrower key. Gateway policy and provider authorization are complementary controls, not substitutes. Microsoft’s guidance on least privilege for AI agents similarly emphasizes scoped identities, tools, resources, and recovery paths.

For ActionDock, the current connection boundary is intentionally specific: public HTTPS REST endpoints using a bearer token or API-key header. The owner configures allowed methods and normalized path prefixes. Private endpoints, OAuth-only integrations, browser-only systems, and unattended high-volume writes are outside the present fit.

Read the detailed API connection boundary before selecting a target.

2. Submit a structured proposal, not an open-ended instruction

The agent should submit the exact operation it wants performed. A request such as “fix the account” is not reviewable. A request containing PATCH /accounts/42 and a small JSON body is.

Structure makes deterministic checks possible. The gateway can compare the requested method and path with owner-configured policy before any credential is used. Optional semantic analysis may add context, but it must not expand what deterministic policy permits.

The agent should also use a stable workflow identity and idempotency key for the same logical submission. This can deduplicate work at the gateway boundary. It cannot guarantee exactly-once behavior in an arbitrary provider; the separate guide to AI agent API retries and idempotency explains that limit.

3. Bind approval to the exact request

“Approve this tool” is too vague for a consequential write. The reviewer needs the resolved destination, method, path, query, body, and the connection version that will supply the credential.

The approval must refer to that specific snapshot. If the connection changes while the request waits, the old decision should no longer release it. The agent also should not be able to approve its own request with the same API credential it used to submit the job.

This is why approval is a state, not a conversational courtesy. The job remains awaiting_approval until the signed-in owner approves or rejects it. Only then may the approved snapshot enter execution. See the full guide to human-in-the-loop approval for AI agents and the current ActionDock approval contract.

4. Inject the target credential after approval

The target-system credential should stay outside the agent’s prompt, context, output, and tool arguments. The execution service retrieves it only when dispatching an approved request.

This separates two capabilities:

Those credentials should not be interchangeable or returned to the agent. The practical guide to giving agents API access without exposing keys covers rotation, provider scopes, and bypass prevention in more detail.

5. Record the outcome without overstating it

After dispatch, the system should preserve what it observed: the submitted intent, policy and approval state, terminal execution status, and response received from the provider.

That record supports debugging and handoff. It is not independent attestation of the provider’s current external state. A provider can accept a request and then drop the connection before returning a usable response. In that case, automatic retry can duplicate the effect.

A safer terminal state is execution_unknown: stop blind retry, inspect the target system, and decide whether a new request is necessary. This is part of the durable actions workflow, not an exactly-once guarantee.

How to choose the first write

The first safe write should be useful enough to repeat and narrow enough to inspect. Use this checklist before building the connection:

  1. Start with an existing agent. It already produces a recommendation or payload that someone uses at least weekly.
  2. Name one manual handoff. A person currently copies the recommendation into a business system or asks an engineer to run a script.
  3. Choose one endpoint family. Avoid a general-purpose administrator API or wildcard path.
  4. Assign one owner. Someone understands the target record and can judge the exact proposed change.
  5. Keep volume reviewable. The current pattern is designed for low-to-moderate writes reviewed one job at a time.
  6. Plan reconciliation. Decide how to read the resulting state if delivery becomes uncertain.
  7. Remove the alternate credential. If the agent retains direct write access, the supervised path is optional rather than enforceable.

A good first example is changing a reviewed status field on one internal record. A poor first example is granting the agent broad administrative access and relying on its prompt to stay within scope.

What the gateway does—and does not—control

NIST’s 2026 summary of AI-agent security responses reports broad agreement that established cybersecurity principles remain relevant but require adaptation for agent systems. The practical adaptation here is complete mediation for a specific action channel.

ActionDock can check requests routed through its MCP or HTTP API, keep a configured credential server-side, require owner approval, suppress automatic retry after an ambiguous outcome, and preserve the execution state it observed.

It cannot control the agent’s reasoning, browser, computer, native integrations, or credentials held elsewhere. It does not certify that a workflow is compliant. It does not guarantee that the provider applied an effect once, or that the provider’s current state still matches the recorded response.

These limits are not footnotes. They define the deployment work required to turn a supervised gateway into a meaningful boundary.

Frequently asked questions

Is human approval enough to secure an AI agent write?

No. Approval should sit behind deterministic destination and operation policy, show the exact request, and use a credential unavailable to the agent. The reviewer also needs a manageable volume and enough context to make a real decision.

Does an API gateway control every action the agent can take?

No. It controls only requests that pass through that gateway. Direct API keys, authenticated browser sessions, and other connectors bypass the boundary unless they are removed or restricted.

Does an execution record prove the target system’s final state?

No. It records what the gateway submitted and the response it received. If the response is missing or ambiguous, reconcile against the provider before retrying or claiming success.

Move one useful agent beyond read-only

Start with the write your team still performs by hand. Review the First Safe Write workflow, then describe the blocked write with the target API, method, path, reviewer, and expected result.