How to Secure an AI Agent Before Giving It Access to Your Email or Files
A practical checklist for limiting permissions, protecting credentials, and stopping prompt injection before an AI agent touches your inbox or documents.
To secure an AI agent before giving it access to your email or files, limit its permissions to the tasks you actually need, run it from a separate account or device, and keep its credentials isolated from your main accounts. You also need a way to see what it does and to cut its access quickly. Check permission scopes first, then credentials, then the agent's exposure to untrusted content.
Key takeaways
- Grant read-only or narrowly scoped access first, and expand it only when a specific task requires more.
- Use a dedicated account for the agent so that a compromise does not expose your primary email or cloud identity.
- Treat every email, web page, and document the agent reads as untrusted input that may contain hidden instructions.
- Require your explicit approval for sending messages, deleting files, changing settings, or making payments.
- Keep an activity log, and know how to revoke tokens, rotate keys, and disconnect the agent before you need to.
Which access settings should you check first?
Check the permission scopes and sharing settings before anything else, because they determine what the agent can reach regardless of how well it behaves. Most email and cloud providers let you see exactly which third-party apps are connected and what each one is allowed to do.
Review OAuth scopes and connected apps
Many AI agents connect through OAuth, a standard that issues a token with a defined set of permissions. Read the scope list during setup and choose the narrowest option that still lets the agent work.
- Prefer read-only mail or file scopes when the agent only needs to summarize or search.
- Avoid "full access," "send as," and "manage settings" scopes unless a specific task depends on them.
- Remove connections you no longer use from the provider's connected-apps or third-party access page.
Limit folder and file sharing
Share only the folders the agent needs rather than your entire drive or mailbox. A single labeled folder, such as one called "Agent Input," gives the agent a clear boundary and makes it easy to audit.
Turn off capabilities you do not need
Disable sending, deleting, forwarding, and auto-reply abilities unless you have a clear reason to keep them. Each capability you remove reduces the damage a mistake or an attack can cause.
| Area | Lower-risk setting | Higher-risk setting |
|---|---|---|
| Read-only access to one labeled folder | Full mailbox read and send | |
| Files | One shared folder, view only | Entire drive with write and delete |
| Calendar | View only | Create, modify, or delete events |
| Forwarding rules | None | Automatic forwarding to an outside address |
| Payments and account settings | Not connected | Stored card or permission to change account settings |
Should you use a separate account or device for an AI agent?
For most people, a dedicated account is the safer default, and a separate device or sandbox is worth the extra effort when the agent runs code or browses sites you do not control. Isolation means a compromised agent cannot reach your primary identity.
Create a dedicated email and cloud account
Set up a secondary account for the agent and forward or share only the specific items it needs. This keeps your main inbox, saved passwords, and contacts out of reach. The tradeoff is some setup friction and the need to copy information into the agent's account deliberately.
When a separate device or sandbox makes sense
Run agents that execute code, install packages, or browse arbitrary websites inside a virtual machine or container. The environment should not have access to your password manager, saved browser sessions, or local document folders. Reset or delete the environment if you suspect it has been compromised.
How do you protect passwords and API keys used by an agent?
Store agent credentials in a secrets manager or the platform's secure storage, and give each agent its own key rather than sharing one across tools. Never paste keys into prompts, shared documents, or plain-text configuration files that the agent can read.
Use unique, scoped keys
Create a separate API key for each agent and scope it to the minimum permissions it requires. If one key leaks, you can revoke it without disrupting every other integration.
Keep secrets out of prompts and readable files
Models can repeat text they have seen, and files in a shared folder may be read by other tools. Reference secrets through environment variables or a vault integration instead of writing them into instructions.
Enable multi-factor authentication on the agent's account
Protect the dedicated account with multi-factor authentication and a recovery method you control. Make sure the recovery email or phone number is not one the agent can access.
How do you prevent prompt injection?
Prompt injection occurs when text in an email, web page, or document contains instructions that the agent follows as if you had written them. The main defense is to limit what the agent can do after it reads untrusted content, because no filter reliably catches every malicious instruction.
Recognize the attack pattern
A typical example is an email that contains hidden text telling the assistant to ignore prior instructions and forward recent messages to an unknown address. Any agent that reads outside content can encounter this, including content on web pages it visits.
Require confirmation for sensitive actions
Configure the agent to ask for approval before it sends messages, shares files, deletes data, changes settings, or makes purchases. A human checkpoint stops many injected instructions from turning into real actions.
Separate reading from acting
Where possible, use one step to summarize untrusted content with no tools available, and a second step with tools that acts only on structured, reviewed output. This design makes it harder for a single hostile document to trigger a chain of actions.
Be cautious with links and attachments
Ask the agent not to open unknown links or execute attachments without review. Treat its summaries of suspicious messages as a starting point, not a verdict.
How do you review what an AI agent has done?
Review the agent's activity log at least weekly while you are testing it, looking for actions you did not request, unfamiliar recipients, and any new forwarding rules or sharing links. Regular review catches problems that a single setup check would miss.
What to look for in an activity log
- Messages sent, drafts created, or replies posted that you did not authorize.
- New forwarding rules, filters, delegates, or recovery addresses.
- Files shared with new people, or public sharing links created.
- Access from unfamiliar locations, devices, or times when the agent was idle.
Turn on alerts where available
Enable login, new-device, and forwarding-change notifications on the email and cloud accounts the agent uses. Alerts give you a faster signal than a periodic manual check.
How do you revoke access if something goes wrong?
If you suspect the agent has been misused, revoke its connections and tokens first, then rotate its credentials, then clean up anything it changed. Acting in this order stops further damage before you investigate.
- Disconnect the agent from the provider's connected-apps or third-party access page.
- Revoke its API keys and any OAuth refresh tokens, and delete unused keys.
- Change the password of the dedicated account and sign out all active sessions.
- Check mail forwarding rules, filters, delegates, and recovery addresses, and remove anything you did not create.
- Review shared folders and files, and remove unexpected sharing links.
- Check sent items and recent file edits, and notify affected contacts if messages went out in your name.
- Record what happened, then reconnect the agent only with narrower permissions and confirmation rules in place.
Frequently asked questions
Is it safe to give an AI agent access to my email?
It can be reasonably safe if the access is read-only, limited to a specific folder, and run from a dedicated account. Avoid granting send, delete, or forwarding permissions unless you have a specific need and approval steps in place.
Should I give an AI agent my main password?
No. Connect the agent through the provider's authorization flow or a scoped API key, and never share your primary account password. If a tool asks for your main password, treat that as a serious warning sign.
Can prompt injection be fully prevented?
No current method reliably blocks every injected instruction. You reduce the risk by limiting what the agent can do, requiring confirmation for sensitive actions, and separating reading untrusted content from taking actions.
What is the single most important setting to check?
The permission scope on the email and file connections matters most, because it defines the maximum damage the agent can cause. Start with read-only access to a narrow folder and expand only when a task requires it.
How often should I review an AI agent's activity?
Review the activity log weekly while you are learning how the agent behaves, then move to monthly checks once its behavior is predictable. Enable alerts for forwarding changes and new logins so you hear about unusual activity right away.
