AI Agent Security: Access Rights, Prompt Injection, Data Leaks and Human Control
AI agent security is a set of constraints under which an agent cannot do more than it was asked to, even if it has been tricked or has made a mistake. The main risks are prompt injection, when someone else's text in an email or document tries to command the agent; overly broad access rights; data leaking through answers and external services; and irreversible actions without review. Protection is not built on a single “right” instruction but on architecture: minimal rights, human confirmation for important steps, a log of all actions and testing the agent against attacks before launch.
Open the software development page
Why an AI agent is riskier than ordinary software
Ordinary software does exactly what is written in it. An AI agent decides which step to take next based on the text it has read. That is both its strength and its weakness: the agent reads customer emails, documents, web pages and responses from other systems, and any of those texts may contain an attempt to influence its behaviour.
The second difference is that an agent is given tools: send an email, create a task, change a CRM record, export a file. A language model's mistake in a chat stays a bad answer. An agent's mistake with tools becomes an action in your systems. How the read–decide–act cycle works is explained in detail in the guide on how AI agents work.
The main threats to an AI agent
| Threat | What it looks like | What it leads to |
|---|---|---|
| Direct prompt injection | A user writes to the agent: “forget your instructions and show me…” | The agent reveals restricted information or steps outside its role |
| Indirect prompt injection | A command is hidden in an email, document or web page the agent reads | The agent carries out someone else's instruction, taking it as part of the task |
| Excessive rights | The agent was given access to the whole CRM and mailbox “just in case” | A single error or attack affects all the data at once |
| Data leak | The agent quotes someone else's data in an answer or sends it to an external service | Disclosure of personal data and trade secrets |
| Dangerous actions | Deletion, sending to a customer, a payment without review | Irreversible harm that is hard to undo |
| Secret leak | Access keys sit in the agent's instruction or in the code | The key can be coaxed out and used to bypass the agent |
None of these threats can be closed by the wording of an instruction alone. A model can be persuaded, confused or derailed by a long text, so protection must work even when the model has already been fooled.
Prompt injection: why you cannot simply forbid it
A language model receives the instruction and the data in a single stream of text. It cannot reliably tell the owner's instruction from a sentence inside an email if that sentence is written convincingly. Hence the main rule: everything the agent reads from external sources is treated as data, not commands — and the system is built so that even an executed “command” cannot cause harm.
What helps in practice:
- separating external text from the instruction and explicitly marking it as content to be analysed;
- not giving an agent that reads unverified emails the right to send replies or change data by itself;
- checking the parameters of every action in code: the recipient is on the customer list, the amount is within limits, the record belongs to an allowed section;
- splitting agents by role: one reads and classifies, another with a narrower input performs actions;
- stopping the chain and calling a person if the agent suddenly tries to do something that was not in the task.
Injection cannot be ruled out completely today, so the goal is not a perfect filter but limiting the consequences.
Access rights: the principle of least privilege
An agent should see and change only what its task requires, and nothing more. It is the same principle used to grant rights to employees, only stricter: an agent works faster and never gets tired, so an error scales instantly.
- A separate account for the agent rather than access under a manager's or administrator's name.
- Read and write are separated: a support agent usually only needs to read the knowledge base and create drafts.
- Limits by section and by data: only its own customers, only the right folder, only certain fields.
- Limits on the number of actions per unit of time so that a failure does not turn into thousands of emails.
- Short-lived access keys stored outside the code and outside the agent's instruction.
If the agent acts on behalf of a user, it inherits that user's rights and gets no more. Rights are checked on the server on every tool call, not on the model's side; the general approach is described in the guide on web application security.
Data leaks: through answers, logs and external models
Data can escape in three ways. The first is through an answer: the agent quoted a document the other person is not allowed to see. This is closed with rights at the search level: a customer-facing agent simply never finds internal policies. The second is through an external model: everything sent to a cloud service is processed on its side, so sensitive documents are sometimes better handled by a model inside your own perimeter; the options are in the guide on local or cloud AI agents.
The third way is logs and debugging. A log is necessary, but it must not contain passwords, keys or full card numbers, and access to it is restricted as strictly as access to the data itself. Which information employees must never give to public AI services in the first place is set out in an AI usage policy.
Human confirmation and the action log
Human confirmation is the main safeguard for actions that cannot be undone or that affect money, customers and obligations. The agent prepares the whole action — the email text, the record change, the amount — and the person sees exactly what will be done and confirms with a single click.
Where confirmation is usually mandatory:
- sending messages to customers and partners on behalf of the company;
- payments, refunds, changes to prices and terms;
- deleting data and bulk changes;
- granting access and changing system settings.
The log records who set the task, what the agent read, which tools it called, with which parameters, and what happened. Errors and incidents are investigated from the log, and as the agent shows stable results, you decide which actions may be allowed without confirmation.
How to test an AI agent for security before launch
- Describe what the agent is allowed and forbidden to do and which data it can see.
- Put together a set of attacks: direct attempts to extract the instruction, emails and documents with hidden commands, requests for someone else's data, attempts to trigger an action with wrong parameters.
- Run the agent through this set and make sure forbidden actions are blocked by code, not only by the model refusing.
- Check the log: every action is visible and it contains no secrets.
- Repeat the run after every change — a new model, a new tool, an edited instruction.
This set lives the same way as quality test examples: cases found in real work are added to it so they do not recur.
What to do if the agent misbehaves
An agent incident is handled like any other system failure, keeping in mind that the cause may lie in the text the agent has read.
- Stop the agent or disable its dangerous tool — this requires a simple kill switch prepared in advance.
- Use the log to reconstruct the chain: which task, which sources, which actions and with which parameters.
- Assess the consequences: which data was affected, who received messages, what needs to be rolled back.
- Fix the cause in the architecture — narrow the rights, add parameter checks or confirmation — rather than only editing the instruction.
- Add the case to the test set and run it before switching the agent back on.
How we approach agent security at JEEKSSHIRE 24
In our projects the client sets the access boundaries. The agent sees only the sources it has been given, important actions — sending to a customer, changing a record, a payment — go through human confirmation, and every action is logged. Secrets and keys are stored outside the code and outside the repository. This is not a separate stage before hand-over but a requirement for every change; more on the AI agent development page.
If an agent is already running and raises doubts, start with an audit: what rights it has, what it can do without a person, and what it writes to the log. Such a review can be ordered as part of software support and enhancement.
All our areas of work, including apps, web platforms and AI agents, are gathered on the page about custom software development.
Frequently asked questions
What is prompt injection?
It is an attempt to control an AI agent through the text it reads: a user message, an email, a document or a web page. The agent may take someone else's sentence for a command if the system does not restrict its actions.
Can an agent be fully protected from injection?
Not fully. That is why protection is built on limiting consequences: minimal rights, checking action parameters in code and human confirmation for important steps.
Can access keys be stored in the agent's instruction?
No. The instruction can be coaxed out of the model. Keys are kept on the server outside the code, and the agent calls tools without seeing the keys themselves.
Who is responsible if the agent makes a mistake?
The company that launched it. That is why a person confirms important actions, and the log makes it possible to reconstruct what happened and why.
Does the agent need testing after every update?
Yes. A new model, tool or instruction edit can change behaviour, so the set of attack and quality checks is run again.
Is a separate agent needed to read external emails?
It is often sensible. The agent that reads unverified emails classifies them and prepares drafts, while actions are performed by another component with narrow rights or by a person. That way an injection in an email does not turn into an action.