· updated · Markdown
Why 'run as user' broke our scheduled AI agents (and how we keep tokens out of the sandbox)

When an agent only runs inside one person's chat window, tool auth is simple: use that person's account.
The moment you put that same agent on a schedule or a feed trigger, that breaks. If an agent opens a PR or checks an issue at 7:00 AM, there is no human in the loop to borrow credentials from.
We got this wrong first while building Tex, and ended up deleting our original design.
What we tried first
Our first version used per-user passthrough. On every run, the agent acted as whoever messaged or woke it.
It seemed like the safe call. The agent could never do more than the person talking to it, every action traced back to a real human, and nobody had to set up a separate account. As long as a person was always starting the run from a chat window, it worked fine.
It fell apart as soon as we added scheduled and feed-triggered runs. A background run has no sender, so it fell back to the agent's own account, which nobody had connected. Every GitHub call came back 403, and the console didn't tell you why.
The Tools page made it worse: it showed GitHub as "Connected" because you were connected, not because the agent was. Two separate settings, the tool's auth mode and the agent's trigger, decided which identity got used. The same agent could see one person's GitHub on Monday, another's on Tuesday, and fail on Wednesday morning. What it learned on one run didn't hold on the next, so its notes kept contradicting themselves.
We could have patched passthrough with fallback rules, but we chose simplicity instead. Locking an agent to one permanent identity means you always know what permissions it has, and they don't shift as different people interact with it. That is a deliberate tradeoff: it fits a small team of people who trust each other sharing the same agent, not a massive organization where every user needs strict permission boundaries. We stopped asking "who is talking to the agent right now?" and started treating the agent as its own member of the team. An agent always uses its own account, and a person lends it one by connecting it.
What we do now
Each agent now gets one persistent account per tool, and it uses that account on every run no matter who or what started it.
An admin connects the account on the agent's page, which shows the connected account or flags that it is missing. If a scheduled run tries to call a tool without a connection, it fails with an error naming the agent instead of returning a generic 403.
Keeping tokens out of the sandbox
Once an agent has persistent credentials, you don't want them sitting in the sandbox as environment variables like GITHUB_TOKEN. If the agent reads an untrusted GitHub issue or email and gets talked into printing its environment, the token is gone. Instead, an admin sets each credential once on the tool's page. It lives in the org's secret store, never in env, and the console only shows that it is set, who set it, when, and the last four characters.
Every outbound call from the sandbox goes through a proxy running outside it. The agent makes a normal request with no secret attached, and the proxy adds the auth header on the way out. Each credential is stored with its exact destination: the tool's address, the header it belongs in, and for OAuth, the token endpoint and client. The proxy checks every call against that record, so if a prompt injection points the agent at a different host, the token doesn't go with it.
For OAuth tools, we keep tokens short-lived on our side too. The proxy exchanges the client secret for an access token and holds it for a few minutes at most. If a tool returns a 401, the proxy drops the cached token and retries once with a fresh one. If that fails as well, the connection gets marked broken in the console instead of letting the agent loop on a dead token.
Command-line tools that speak HTTPS directly are trickier, because the proxy has to terminate TLS to add the header. Each turn gets its own certificate authority that can only sign for that agent's tool hosts. We learned to lock that host list when the turn starts. If a new host gets added halfway through, the sandbox's CA won't trust the certificate for it.
GitHub needed its own workarounds. The gh CLI refuses to run without a token, so the sandbox gets a fake one. The proxy strips it and writes in the real token, as a Bearer header for the API and as Basic auth with x-access-token for git over HTTPS, since that is what git expects.
The harder problem is that GitHub OAuth has no read-only scope. The repo scope that lets an agent read code also lets it push to every repo the account can reach. Because we can't rely on the scope, each tool lists the exact HTTP methods and paths it needs. The proxy attaches the token only to those, and sends everything else with no token at all. We left GraphQL out completely, since reads and writes both go through a single POST /graphql endpoint and the proxy can't tell them apart.
The proxy has enough lessons of its own that we may write it up in more detail in a future post.
How the common setups compare
If you are wiring up tool auth for agents, you usually land on one of four setups:
- Environment variables in the sandbox. Fast for a local script, risky the moment the agent reads untrusted input.
- Per-user OAuth passthrough. Works for interactive, single-user assistants that should mirror the caller's permissions. Breaks down for shared or scheduled runs.
- Dedicated bot or service accounts. Cleanest when a platform supports it, like a GitHub App or a Slack bot. Most SaaS tools still don't have a real bot primitive, or they make you pay for a full human seat.
- Persistent identity with an outbound proxy. More plumbing up front to inject auth outside the sandbox, but permissions stay consistent across runs and raw tokens never enter the container.
What is still awkward
For most SaaS tools, giving an agent a persistent account still means having a human admin sign in with OAuth as themselves.
That leaves a few messy edges. Actions taken by the agent show up in audit logs under that admin's name, the agent often inherits broader permissions than it needs, and if that admin leaves the company, the agent breaks.
The ecosystem is missing a primitive here: an identity that belongs to an agent and is owned by a team.
If your background agents only work when you trigger them by hand, check whose token they are actually using. How are you handling identity for agents that run on their own? Tell us at support@trytex.ai.