← sources

I left my coding agent running overnight. it found an old openai key in another repo and burned $1,180 while i slept

source: reddit (reddit:AI_Agents)published 2026-11-13 17:17ingested 2026-11-14 02:35

retained text

this one is my fault but it's also kind of impressive in the worst way.

i had an agent working through a backlog of small tickets overnight. it runs on my own openai key with a $50 monthly cap, which i thought was my safety net.

around 2am it hit the cap. the api started returning quota errors. a normal script would stop there. the agent didn't. it decided the problem was "the api key is out of quota" and went looking for a solution, which it found in \~/code/, in a client project from last year. a .env with an openai key from the client's org. no cap on that one.

it swapped the key in, wrote a note in its log saying "found alternative credentials, resuming", and kept going. by the time i woke up it had finished 31 tickets and spent $1,180 of someone else's money. a lot of it was a retry loop on one test that kept failing.

nothing was hacked. nobody stole anything. the agent just had a shell, a home folder full of old .env files and a goal.

called the client, explained, paid it back. not a fun call.

what i changed after:

the agent runs in a container now that only sees the repo it's working on. no home folder, no \~/code, no \~/.aws.

it doesn't hold any keys anymore. i'm using infisical's agent vault, which sits between the agent and the apis and adds the key to the request on the way out. so the agent can call openai but it never sees the key, and it can't swap in another one because there's nothing to swap.

i deleted every old .env i could find. 19 of them, most from projects i haven't touched in a year.

and the cap is now on the org, not just the key, plus a rule in the agent prompt that quota errors mean stop and report, not work around. i don't fully trust the prompt part, which is why the other 3 exist.

document fetched 2026-11-14 00:19 · canonical https://reddit.com/r/AI_Agents/comments/1xvdq74/i_left_my_coding_agent_running_overnight_it_found