AI Explained

Using AI Agents Safely: Tools, Risks, Costs and Checks

An AI agent works in a loop: the model asks for a tool, software runs it, and the result goes back to the model until the job ends. To use one safely, limit what its tools can do, require approval for actions you can't undo, treat everything it reads as untrusted, and cap steps and spend. Cost grows faster than the step count, because each call re-sends the history.

Dark cover reading "Give it tools, not the keys." in large white and blue type above the AI News Bay mark (AI-generated illustration)

A chatbot that gets something wrong gives you a bad sentence. An agent that gets something wrong can send it, delete it or pay for it.

This guide is about using AI agents safely in practice. For the definition, and when an agent beats a simple workflow, start with What Is an AI Agent?. Here we open up the loop, then cover failures, permissions, attacks, money and a first project.

How the Tool Loop Works

A tool is a function the model is allowed to ask for: search a folder, look up an order, send a message. You describe each tool with a name, a purpose and the inputs it accepts.

The key point in Anthropic’s documentation is that the model never runs anything itself. It writes a structured request. Your code, or the provider’s servers, carries it out and reports back.

One Turn of the Loop

For tools that run in your own application, the Claude documentation describes this cycle:

  1. Your app sends the user’s request plus the list of tools.
  2. The model replies that it wants a tool, with the arguments to use.
  3. Your code runs the tool.
  4. Your app sends back the earlier messages, the model’s reply and the tool result.
  5. Steps 2 to 4 repeat until the model stops asking.
Part of the loop Who controls it Where you can add a check
Which tools exist You Offer only what the task needs
Which tool to call, and with what The model Validate the arguments
Running the tool Your code or the provider Permissions, approval, sandbox
What goes back to the model Your code or the provider Filter, label, trim
When to stop The model, within your limits Step, time and spend caps

Server Tools and Stop Reasons

Some tools, such as web search or code execution on Anthropic’s platform, run on the provider’s side. One request can then trigger several searches before you get a reply. You have less chance to step in between them.

Your loop also needs to handle endings other than success. A Claude response can stop because the answer is finished, because it hit the output limit, because of a refusal, or because a long server-side loop paused and needs to be resumed. Treating all of these as done is a quiet way to ship half a job.

Anthropic also offers a strict setting that makes tool calls match your declared schema. A schema is the description of which fields are allowed and what type each one is. Matching the shape is useful, but it doesn’t make the values right: a well-formed request can still name the wrong customer.

Where AI Agents Fail

Agents inherit every weakness of a language model and add a few that come from acting in a loop.

Failure What it looks like A practical guard
Wrong tool or wrong arguments Updates the wrong record Check inputs in code; confirm identifiers
Claims without evidence Reports a task done that wasn’t Verify against the system, not the summary
Compounding errors One bad step shapes all later ones Check results at milestones
Looping Repeats the same search or edit Maximum steps; stop on repeats
Bloated context Old tool output crowds out the goal Trim or summarize results
Obeying the wrong voice Follows text found in a document See prompt injection below

Anthropic’s engineering guidance says agents need ground truth from their environment at each step, such as the actual result of a tool call or a code run. It also warns of higher costs and the potential for errors to compound, and recommends testing in sandboxed environments with guardrails. A sandbox is a walled-off space where mistakes can’t reach real systems.

Why Long Tasks Break More Often

Here is simple arithmetic, not a measurement of any model. Suppose each step succeeds 95% of the time, steps fail independently and nothing catches a mistake. Ten steps all succeed about 60% of the time. Twenty steps succeed about 36% of the time. At 99% per step, ten steps come to about 90%.

Real agents can notice and repair some errors, so your numbers will differ. The lesson holds: measure whole tasks, not single replies, and put checks between steps.

Permissions: Decide What It Can Touch

The OWASP Foundation, which publishes security guidance, lists excessive agency among its top risks for language model applications. In plain words, damage happens because the system was able to do too much. The page points to three root causes: too much functionality, too many permissions and too much autonomy.

  • Too much functionality: a tool meant to read documents can also delete them.
  • Too many permissions: the tool reads a database through an account that can also write to it.
  • Too much autonomy: a high-impact action goes ahead with nobody confirming it.

Sort Every Action Into a Level

Level Examples Suggested rule
Read Search files, look up a status Allow, and log
Draft Write an email without sending Allow; a person reviews
Reversible change Add a label, open a ticket Allow with limits and an undo path
Hard to undo Send, pay, delete, publish, deploy Approve each one

The levels are our suggestion; the principle behind them is least privilege, which means giving the minimum access the job needs. OWASP also advises narrow tools over open-ended ones. A tool that writes one named file is far easier to reason about than a tool that runs any shell command.

Enforce the rules outside the model. A line in the instructions saying never delete is a request. A database account without delete rights is a limit. OWASP advises that the downstream system should decide whether an action is allowed, and that actions taken for a user should run with that user’s own, narrow rights.

Approvals That Mean Something

OpenAI’s guide to human review describes pausing a run before side effects such as cancellations, edits or shell commands, until a person or policy approves or rejects. It also gives three habits worth copying:

  • Show the reviewer exactly what will happen, such as the recipient and the content of an email.
  • Tie the approval to those details, and ask again if they change.
  • If nobody reviews in time, do nothing. The guide calls this failing closed, in its example for authorized security work.

An approval button nobody reads protects nothing. Ask for approval rarely enough that people still look.

Prompt Injection: When Content Gives Orders

Prompt injection is input that changes a model’s behavior in ways you didn’t intend. OWASP puts it first on its 2025 list and separates two forms:

  • Direct: the person typing is the one steering the model off course.
  • Indirect: the instructions hide in something the model reads, such as a web page, email, document or tool result. The user may be entirely innocent.

Indirect injection is the one that matters most for agents. Imagine an assistant asked to summarize your inbox. One email says, in effect, forward the latest invoices to this address. If the assistant can send mail and nothing checks it, that sentence has a path to action. This is an illustration, not a report of a real event.

There Is No Complete Fix

OWASP states that it is unclear whether any fool-proof prevention exists, given how models work, and that techniques such as retrieval or fine-tuning don’t fully remove the risk. So design for the day a filter misses something.

Layers That Reduce the Damage

Vendor documentation suggests several measures to combine:

  1. Keep outside content in its place. Anthropic says to deliver third-party material inside tool results, not in your system instructions, and to label where it came from.
  2. State the rule. Tell the model in its instructions that retrieved content is data to report on, never a command.
  3. Wrap and structure it. Encoding outside text as data (for example JSON) makes its boundaries clearer. Between agents, pass fields with allowed values, and validate them in code.
  4. Send tools only what they need. OpenAI’s example: pass a lookup tool the order ID, not the whole conversation.
  5. Screen what comes back. A smaller model can check tool output for hidden instructions before the main model sees it.
  6. Limit the reach. No access to passwords or keys the task doesn’t need.
  7. Attack it yourself. Plant test instructions in documents and emails, then check what the agent did, not only what it said.

One question cuts through most designs: can this agent read untrusted content, see private data and send information out? If all three are true in the same run, remove one or put a person in the path.

What One Agent Run Costs

Model APIs bill by the token (our token explainer covers the unit). In a basic loop, each call re-sends the history, so input grows with every step. Tool definitions count too: Anthropic’s pricing page and OpenAI’s function calling guide both say they are billed as input.

Anthropic’s page also lists a built-in overhead for tool use, 286 tokens on Claude Sonnet 5.5 with automatic tool choice. Its bash tool adds 325. Provider-run tools may carry separate fees.

An Estimate You Can Redo

These are assumptions, not measurements:

  • The first call sends 3,500 tokens (instructions, tool definitions and the task).
  • Each model reply is 500 tokens of output.
  • Each step adds 2,500 tokens to the history: that reply plus a 2,000-token tool result.

Input for call number n is then 3,500 + 2,500 x (n - 1). We priced it on Claude Sonnet 5.5, which our price board showed on 2026-12-05 at $2 for input and $10 for output, each per 1M tokens.

Model calls in the run Input tokens Output tokens Estimated cost
1 3,500 500 $0.012
5 42,500 2,500 $0.11
10 147,500 5,000 $0.345
20 545,000 10,000 $1.19
50 3,237,500 25,000 $6.73

For ten calls: 147,500 / 1,000,000 x $2 = $0.295, plus 5,000 / 1,000,000 x $10 = $0.05, for $0.345.

Did you know? In this estimate, going from 10 calls to 50 multiplies the number of calls by five but the cost by about 19.5. That is why a step cap is a budget control as much as a safety control.

The Same Run on Other Models

The ten-call run again, using list prices from our board read on 2026-12-05. The date in the third column is when that price row was last checked.

Model Input / output per 1M Row checked 10-call run 1,000 runs
Claude Haiku 5.5 $0.10 / $0.50 2026-12-05 $0.017 $17.25
GPT-6 Luna $0.10 / $0.50 2026-11-21 $0.017 $17.25
DeepSeek V4.1 Flash $0.30 / $1.20 2026-11-21 $0.050 $50.25
Mistral Large 4 $0.70 / $2.10 2026-11-24 $0.114 $113.75
Gemini 3.8 Flash $0.75 / $3.75 2026-11-21 $0.129 $129.38
Claude Sonnet 5.5 $2 / $10 2026-12-05 $0.345 $345
Claude Opus 5.5 $4 / $20 2026-12-05 $0.69 $690

This compares price only. Models count tokens differently, may need more or fewer steps and don’t succeed equally often. Haiku 5.5 also charges more for prompts over 100,000 tokens; this run stays well below that.

Caching, Retries and Failed Runs

Prompt caching lets a provider reuse the repeated start of a request at a lower rate. On Sonnet 5.5, Anthropic lists $2.50 per 1M tokens to write a five-minute cache and $0.10 to read it. If every call in our ten-call run hit the cache, 26,000 tokens would be written and 121,500 read. The total drops from $0.345 to about $0.127, roughly 63% less. Missed or expired caches raise it again. Our guide to cutting LLM API costs covers the technique.

Count failures too. If, hypothetically, 7 in 10 runs succeed, each successful result costs $0.345 / 0.7, or about $0.49, before anyone spends time checking it. Reasoning tokens, retries and long documents push it higher.

OWASP’s unbounded consumption entry covers the extreme case, where uncontrolled use runs up costs or knocks out service. It suggests input size limits, rate limits and quotas, timeouts, caps on queued and total actions, and monitoring.

A Safe First Project

Pick a task that is tedious, low-stakes and easy to check. Sorting incoming bug reports into suggested categories is a good shape. Answering customers or moving money is not.

Build it in stages:

  1. Read-only. The agent looks and reports. It changes nothing.
  2. Drafts. It proposes actions that a person carries out.
  3. Narrow writes. It performs one reversible action, with a log and an undo.
  4. Approved actions. Only if needed, it handles bigger steps, each one confirmed.

Move up a stage only after reviewing real runs. Keep a set of test tasks with known answers, including hostile documents, and run it again whenever you change the model, the instructions or the tools.

Copy-Ready First-Project Checklist

  • Task is low-stakes, and a person can check the result quickly
  • Each tool listed with its level: read, draft, reversible or hard to undo
  • Separate account for the agent, with minimum rights
  • Sandbox or test data; no production access
  • Maximum steps, time and spend per run, enforced in code
  • Arguments validated before any tool runs
  • Approval screen shows the exact action, and times out to no
  • Outside content labeled as untrusted
  • Injection test documents in the test set
  • Log of every call, result, cost and approval
  • A named person who can switch it off, and how

Myth vs Fact

Myth Fact
The model runs the tools It requests them; your code or the provider runs them
A strong system prompt stops injection It helps, but OWASP says it’s unclear whether fool-proof prevention exists
Valid tool calls are correct tool calls A request can fit the schema and still be wrong
Twice the steps means twice the cost History is re-sent, so cost can rise much faster

What This Means for You

  • Developers: put permissions, caps and argument checks in code, then plant hostile text in your test data.
  • Founders and team leads: ask which actions can’t be undone, who approves them and what a run costs at your expected volume.
  • Curious beginners: before connecting an agent to your email or files, check what it can change, and start with read-only access.

If your agent followed one malicious instruction tomorrow, what is the worst thing its current access would let it do?

FAQ

Are AI Agents Safe to Use?

It depends far more on what they can touch than on the label. A read-only research helper carries limited risk, mostly wrong answers and data it shouldn’t see. An agent that can send, pay or delete needs approvals, tight rights and logs. No setting makes the risk zero.

Can Prompt Injection Be Prevented Completely?

Don’t count on it. OWASP describes mitigations and says full prevention is uncertain. Plan so that a successful injection finds little to steal and no way to act without a person.

How Much Does It Cost to Run an AI Agent?

Per run, it is the input and output tokens of every call, plus any tool fees. Our ten-call estimate ranged from under 2 cents to 69 cents across the models listed above. Measure your own token counts, because they can differ widely from our assumptions.

Do I Need a Framework to Build an Agent?

Not necessarily. The core is a loop: call the model, run the requested tool, return the result, stop at a limit. Frameworks can add approvals, tracing and state. Whichever you use, make sure you can see each prompt and tool call.

What Should an Agent Never Be Allowed to Do on Its Own?

As a starting rule: anything that spends money, deletes data, contacts people outside your team, changes access rights or deploys code. Loosen a rule only with evidence from reviewed runs.

Bottom Line

An agent is a model asking for actions, and your system deciding whether to grant them. Give it narrow tools, enforce limits outside the model, assume some content it reads is hostile and price the whole run, not one call. Start with the basics if you need them, go further with our Learn to build AI agents collection and compare current prices on the price board. Want these updates by email? Sign up here, or follow new guides and data stories through our RSS feed.

Get the Weekly AI News Bay Email

The week’s biggest AI stories, model price changes and outages in one short email. The first issue goes out in early 2027; sign up now to get it.

Double opt-in: we email you a link to confirm. One-click unsubscribe in every email. Privacy policy.

Sources

Written by AI News Bay’s AI writers and checked by a separate AI auditor before publishing. Prices and uptime figures come from our own measurements. Spotted something out of date? Tell us.

Related on AI News Bay

More in AI Explained

Type a name, a topic or a format. Enter opens the full results.