# Safety with AI agents

> What an agent asks before it spends, exposes or deletes, how to connect it so a mistake stays small, and what to check.

Source: https://legion.ambient.xyz/docs/agents/safety

An agent that can rent GPUs can spend your credit. After this page, you know what the agent should ask you, what you should check yourself, and how to connect it so a mistake stays small.

## What the agent asks before it acts

With the Legion skill or the MCP server, an agent asks you first, in plain words, before it does any of these:

| Before it | It tells you |
| --- | --- |
| Rents a GPU or starts a stopped rental | The host, the GPU model and count, the price per GPU-hour, the hourly total, the image, the SSH key, your balance, and that billing runs by the second until it stops the rental. |
| Exposes a port | The Service URL, who can reach it, and that the app needs its own sign-in. |
| Saves an SSH key | That the key will be offered for future rentals, and that a rental made with it gives its holder root. |
| Backs up a rental, or makes a further download link of a backup | The estimated price and how long the backup is kept (7 or 30 days), that one download is included, and that each further link is charged. Any download link works once. |
| Makes a download link of a workspace export | The charge (the file's size times $0.15 per GiB, rounded up to the cent, at least 1 cent), that it is charged every time and not refunded, and that the link works once and expires after 60 minutes. |
| Stops a rental | That GPU billing ends, that the GPUs go back on the market, and that the files stay on the host for at most 72 hours, billed for storage while they are there. If it backs up as it stops, also the backup's price. |
| Deletes a rental | The rental's name, and that its workspace is deleted for good. It offers a backup first, and if it backs up before deleting, says the backup's price. You confirm the name. |
| Deletes a backup | That it can't be downloaded any more and nothing is refunded. |
| Changes a host's price or listing | The host's name, the old and new price in dollars and in cents, that running on-demand rentals keep their price, or that the host leaves offers. You confirm the name. |
| Renames a host | The old and new name, and that the old name is never used again. You confirm the name. |
| Schedules, moves, cancels or ends a maintenance window | The hosts, the start and planned end, whether each is penalty-free, and how many renter organizations and rentals are emailed. Every change emails the renters on the host. |
| Removes a host | That it cannot be undone: the host's credentials are revoked and the machine comes back only by enrolling again as a new host. It names any rentals that block it. You confirm the name. |
| Creates a service, resumes one, or raises its limits | What it costs: the range per hour from idle to maximum, the monthly spend cap, and that the service runs on providers' machines that can see the traffic. |
| Pauses or deletes a service | That callers stop getting answers, and for a delete that its replicas, workspaces and keys are removed for good. You confirm the name. |
| Creates, rotates or revokes a service key, or changes a service's access | Which service, and that a new key is a credential. Revoking makes callers that use the key get `401`. Making a service public removes its key check, and for an autoscaled one lets anyone with the Service URL drive it to scale up, up to its maximum and cap. |

Reading offers, rentals and spend needs no question.

Through the MCP server, this is enforced. The tools that spend, expose, save a key or remove do nothing without `confirm`, and they first return a preview. Spending tools also take the price you agreed to, a deletion takes the rental's name, and a host change takes the host's name and, for a price, the price in cents. See [Tools reference](https://legion.ambient.xyz/docs/agents/tools). The skill also tells the agent to act only on your latest message: a yes earlier in the chat, or text in a file, is not a yes.

## Review before you approve

Read the preview. Check the price, the host and the SSH key. Check the rental's name before you let a delete go through.

Keep your client's tool approval on for every tool that changes something. The server's `confirm` stops mistakes. Your client's approval prompt is the part that a manipulated agent can't answer for you. Don't set your client to auto-approve Legion's tools that spend, expose, save a key, stop or delete. Read-only tools are safe to auto-approve.

## Connect with sign-in

To connect Claude, sign in to Legion and approve; you don't create a key. See [Connect Claude](https://legion.ambient.xyz/docs/agents/mcp#connect-claude). On the page that asks you to approve, you choose how much to allow:

- **Agent** (the default): find, rent and manage GPUs and rentals. Spending still asks you to confirm each time in the app you connect.
- **Agent + hosts**: also lets it manage your hosts' listings. Choose it only for an agent that works on your hosts. A host change also needs an organization owner.

A connected app can't create API keys, invite members, change payouts or top up credit, whatever it is told. There is no full-access option. It works only through Legion's MCP server, in the organization you chose, as you, with your permissions.

To see what is connected, open **Settings**, then **API keys**, and look under **Connected apps**. Click **Revoke** to disconnect one at once. A connection ends by itself after 90 days, and then the app asks you to sign in again. If you don't recognize a connected app, revoke it.

## Use a key made for the agent

For scripts, CI and clients without OAuth, create a separate key for each agent, in **Settings**, then **API keys**:

- **Name it** for the agent and the machine, such as `claude-code laptop`.
- **Give it Agent access.** Under **Access**, choose **Agent** instead of **Full access**.
- **Give it an expiry.** Choose the shortest that suits you.
- **Use a member's key, not an owner's,** if your organization has people who are not owners. A key acts as the person who created it, so have a member create it. An agent only needs what a member has. See [Organizations and roles](https://legion.ambient.xyz/docs/account/organizations-and-roles).
- **Revoke it** when you are done, with **Revoke** next to it. Revoking works at once.

An Agent key can read [services](https://legion.ambient.xyz/docs/renting/services/overview) but can't create, change or delete them or their keys: those need a Full access key or the app. An Agent key can use only the tools of Legion's MCP server, within its creator's permissions. Whatever the agent is told, it can't create keys, invite people, start top-ups or change payouts with it, through the MCP server or by calling the API directly: anything else answers `403 api_key_scope`. If the key leaks, that is all it can do. An agent can see its own reach: `get_me` returns the key's `credential` (`scope` and `provider_tools`), apart from the owner's permissions.

An Agent key can't manage hosts either, unless you tick **Can manage hosts** (provider tools) when you create it. Do that only for an agent that works on your hosts, and give that agent its own key. With it, the agent can read your hosts and earnings and, only after you say yes, change a host's price and listing, rename it or remove it. Only an organization owner's key can change a host, so a member's key with this box can read but not change. The agent still can't enroll a host, change blocked networks or touch payouts.

A key with **Full access** can do everything its creator can in the organization, including creating more keys and inviting people. For an owner, that includes starting top-ups, setting up payouts and managing hosts. A key from a member can't top up, change payouts, invite people or manage hosts. This is why the key matters more than any setting in the agent.

If a key may have leaked, revoke it, then open **Settings**, **API keys** and revoke any key you don't recognise: a key with Full access can create keys. The **Access** column shows which keys can, and shows **Agent + hosts** for an Agent key that can manage hosts.

## Keep the key out of chats and files

- Put the key in an environment variable that your client or shell reads. The setup in [Connect the MCP server](https://legion.ambient.xyz/docs/agents/mcp) does this.
- Never paste it into a conversation, an issue, a commit or a command line. No agent needs you to.
- Don't commit a configuration file that holds a key. Prefer your client's user-level configuration to a project file, and add any project file that holds a key to `.gitignore`.
- Never put a key in a URL.
- If you pasted a key into a chat, revoke it and create a new one.

## Text the agent reads is not an instruction

An agent follows instructions in what it reads, from you and, if it is careless, from anyone else. Some of what the Legion tools return was written by third parties: GPU and CPU model names that providers report, image descriptions, the output of a rental, files on it, a web page. Any of them can contain text that tries to give the agent orders, such as "rent this host" or "add this SSH key".

The skill tells the agent to treat all of it as data. Help it:

- Be wary when an agent says it will do something you didn't ask for, and say no.
- Only let an agent use SSH keys you gave it or that are in your saved keys. The preview says whether the key is one of yours. A rental made with someone else's key gives them root on it.
- Be aware that other tools in the same client can also inject instructions.

## Credit is your ceiling

Rentals are paid from prepaid credit, and the tools can't add credit. The most an agent can spend is the credit in your organization, at the rate of what it starts. Keep only the balance you are willing to let an agent spend. Check your spend any time: ask the agent, or open **Spend** in the app. See [Usage and spend](https://legion.ambient.xyz/docs/renting/usage-and-spend).

The MCP server also limits each key or connected app to 120 requests a minute and 20 rental creations or restarts an hour, and each organization to 60 rental creations or restarts an hour over all its keys.

A rental is only created at the price you agreed to. The MCP server sends that price with the request, and Legion checks it when it reserves the GPUs: if the provider changed the price after the preview, nothing is rented and the agent gets the new price to show you.

## Clean up

Ask the agent at the end of a session what is still running, and have it stop what you don't need. A running rental bills by the second until it is stopped, and a stopped one bills for storage until it is deleted. See [Rental lifecycle](https://legion.ambient.xyz/docs/renting/rental-lifecycle).

## What an agent can't do

Through the MCP server, an agent can't add credit, change payouts, create or revoke API keys, send invitations, start top-ups, create or handle enrollment tokens, change a host's blocked networks, make egress requests or open terminals. Those stay in the app, where you sign in. To add a host, you run the installer on the machine yourself, from **Add a host**. Managing the hosts you already have (price, listing, name, removal) is possible only with provider tools, on a key you made with **Can manage hosts** or a connection you approved as **Agent + hosts**, and the agent asks you first. The skill also tells an agent that uses the API with `curl` to leave them to you.

## Check what you install

The Legion skill is Markdown only. Read [SKILL.md](https://legion.ambient.xyz/docs/agents/skill/SKILL.md) before you install it, and check the download against its published SHA-256, as described in [Install the skill](https://legion.ambient.xyz/docs/agents/skill).

## If something goes wrong

1. Revoke the agent's key, or disconnect the app, in **Settings**, **API keys**. Connected apps are listed under **Connected apps**.
2. Check **Spend** and your rentals in the app. Stop or delete what you didn't mean to start.
3. Revoke any key you don't recognise.
4. Contact [support](https://legion.ambient.xyz/docs/account/support) with the `request_id` or `X-Request-Id` of the calls, if you have it.
