---
title: "How AI agents should hold secrets and sign in to tools"
description: "Give each agent a stable identity of its own, connect its tool accounts once, and add tokens outside the sandbox so the agent never holds them. That is how Tex handles secrets."
updated: 2026-11-29
questions:
  - "How do secrets work for AI agents?"
  - "How do I give agents tool access without sharing my passwords?"
  - "How do I stop an agent from leaking my API keys?"
  - "Whose account should an AI agent use when it calls a tool?"
  - "How do I connect an agent to GitHub without putting a token in the sandbox?"
url: https://trytex.ai/answers/ai-agent-secrets-and-tool-sign-ins
---
# How AI agents should hold secrets and sign in to tools

*Updated 2026-11-29. Written by the team that builds Tex, so weigh it accordingly.*

**Short answer:** don't put long-lived tokens where the agent can read them. Store them outside the sandbox and add them to each request on the way out, so a hijacked agent has nothing to copy. And give each agent a stable identity for its tools: one account, connected once, used on every run, rather than borrowing whoever happened to start it.

## Two decisions

**Where the secret lives.** Environment variables and files inside the sandbox are easy, but anything the agent can read, a prompt injection can make it print or send. Safer is a proxy outside the sandbox that holds the secret and adds it to requests the agent makes.

**Whose account the agent uses.** If an agent uses the account of whoever messaged it, the same agent behaves differently depending on who asked, and it is hard to tell what it can do. A stable identity per agent is easier to reason about, audit and revoke. We wrote up how we got there in [Whose account should an agent use?](https://trytex.ai/blog/whose-account-should-an-agent-use)

## How Tex does it

- **Per-agent secrets.** An agent gets only the secrets and tools its definition names.
- **CLI tools such as `gh` and `git`.** The sandbox holds a stand-in token. Tex's egress proxy adds the real one to each request, so the token never enters the sandbox. A tool's request rules can limit which requests get the token, for example only reads of one repository.
- **MCP servers.** A tool with its own API key or OAuth client secret gets it added by Tex on every call; the sandbox never holds it.
- **Sign-ins.** People connect accounts on a tool's page. Each tool names whose account an agent uses: the person who sent the message, or the agent's own.
- **AWS.** A CLI tool can sign AWS requests with a role Tex assumes, so the agent never holds AWS keys.
- **Records.** Each request is on the session's record.

## Questions people ask

**Which services connect?**
Tex has run agents end to end against GitHub (`gh` and `git`) and against Notion, Linear, Sentry, Stripe, Airtable, GitLab, Vercel, Supabase and PostHog as MCP servers. Other MCP servers can be added by address.

**Can the agent still misuse a tool it has?**
It can use the tool within what the account allows. Limit the account, hold risky tool calls for approval, and set a tool's policy to `never` for what it should not do.

## What Tex doesn't do

- Some services refuse Tex's registration as an OAuth client, Intercom among them.

[Try Tex with $10 of free credit](https://trytex.ai/?utm_source=answers&utm_medium=aeo&utm_campaign=ai-agent-secrets-and-tool-sign-ins)
