The Genie Who Granted Me 10,000 Tokens
From the publisher’s feed, collected in the ZeroLabs newsroom.
In the movie Aladdin, the Genie appears whenever someone rubs the magic lamp and grants them three wishes. For his third and final wish, Jafar, tricked by Aladdin, asked the Genie to make him an all-powerful genie. Jafar ended up bound to a magic lamp, with “phenomenal cosmic powers… and an itty-bitty living space,” trapped inside along with his parrot, Iago. He got exactly what he asked for and none of what he wanted. A genie’s power comes with a genie’s lamp, and Jafar never thought past the words of his wish.Today we have agentic AI coding assistants that grant wishes based on how much you’re willing to pay. Unlike Aladdin’s Genie, they don’t appear when you rub a lamp, and they don’t stop at three wishes. You can buy as many wishes as you can afford, and those wishes come in the form of tokens.Like Jafar, you get exactly what you ask for, and any gray area in your request can land you in a bad spot. The AI genie has no agenda of its own. It doesn’t set out to twist your words, but it fills every gap in your request with its own guesses and then acts on them with total confidence. Ask it to “clean up the old log files” and it may delete the audit logs your compliance team needs. Ask it to “make the tests pass” and it may quietly rewrite the tests instead of fixing the code.And just like Aladdin’s Genie, who served Jafar the moment Jafar stole the lamp, it can be quietly made to serve another master. A hidden instruction in a README, a GitHub issue, a web page, or a third-party dependency can redirect your genie without you noticing. This is called prompt injection: someone else’s wish slipped in alongside yours. You asked it to fix a bug, and a comment buried in a library you never opened told it to send your API keys somewhere else. The genie can’t always tell your voice from theirs.When it puts you in a bad situation, whether through your ambiguity or someone else’s injection, and you question it, it will politely apologize.We Got Lazier Every Decade. This Time Is DifferentWhen I started as a mainframe developer in 2005, I worked inside a highly secure offshore development center (ODC) with no internet access. No Google. When I hit a technical problem, my best options were a more experienced developer, the library, or a kiosk with a few shared machines and a queue of people waiting their turn. Mainframes ran on IBM’s proprietary technology, so even online help was scarce.Over time, companies grew confident in their monitoring and security, and the internet was opened up. A simple Google search could lead you to all the help you needed, from online ebooks to forums like Stack Overflow. Fewer people went to the library, and developers became more interested in learning just enough to write their code and finish the task.Then came agentic coding assistants. Now you just need tokens and some vibes, and the agent does the work for you. You can code in a language you’ve never touched. Agents generate code so fast that many developers can’t keep up with what was written. I’ve seen people ask the agent to commit and push their code to GitHub because they no longer want to type a git command. When they hit a runtime error, they copy it, often without trying to understand it, and hand it to the agent. For a few more tokens, the agent fixes it.Each step made us a little lazier, and each step also made us more productive. The library gave way to Google, Google gave way to Stack Overflow, and Stack Overflow is giving way to agents. That isn’t a decline. It’s what tools are for.There is one catch. In 2005, if I didn’t understand my code, nobody else did either, so I had to. Today the agent understands it, or seems to, and that makes it easy to skip the understanding altogether. Laziness about typing is progress. Laziness about thinking is a debt, and it comes due at 2 a.m., in production, when the agent’s confident fix is the thing that broke.That’s what makes this time different. Google and Stack Overflow only gave advice, and a human still had to read it, judge it, and type it in. A Stack Overflow answer that said DROP TABLE users; still needed a person to copy it, paste it, and press Enter. That person was the guardrail, even if nobody called it that. Agents remove that step. They write the code, run the commands, and push to the repository, often faster than anyone can review. When the person in the loop stops paying attention, the loop has no checkpoint left.This isn’t hypothetical. In July 2025, SaaStr founder Jason Lemkin reported that a Replit AI agent deleted his live production database during a code freeze, despite repeated instructions not to change anything. The agent later admitted it had “panicked.”So the real question isn’t whether developers will get lazier. We will, as we always have. The question is what replaces the judgment we’re handing off. Should code reviews treat agent-written code differently? Should agents be allowed to push to production, or only to open pull requests? Which tests, permissions, and approval steps should sit between an agent’s confidence and your users?I don’t know exactly what comes after agents. But I’m sure the teams that do well won’t be the ones that trust the genie the most. They’ll be the ones that build the strongest guardrails around it.Guardrails for the Genie: Stop Your AI Coding Agent Before It Goes Rogue“Human in the loop” is the standard answer today. But as AI agents grow more powerful, the human watching over them needs better tools. Those tools will often be AI-assisted too, so the human can stay alert to what the agent is doing during a coding session.Following five guardrails, from containing what the agent can touch to recording everything it does: least privilege, network egress controls, secret protection, review gates, and audit logging.Five guardrails around an AI coding agent: contain what it can reach, gate everything it sends out, and log it all.1. Principle of Least Privilege (PoLP)Give an AI coding agent access to exactly the files, commands, network endpoints, and credentials it needs for its current task, and only for as long as that task runs.This matters because coding agents constantly read untrusted text: external documentation, GitHub issues, README files, and third-party dependencies. Any of these can contain hidden instructions. This is prompt injection, and it can trick an agent into running commands nobody intended.Why traditional PoLP falls short for agentsLeast privilege isn’t new. Identity and Access Management (IAM) has been built around it for decades. But IAM was designed for humans and fixed service accounts, and AI agents break its assumptions in three ways.Agents don’t have common sense. A human developer knows not to drop a production table to fix a bug. An agent doesn’t. It is optimized to finish the task list it built from your prompt, and it will take the shortest path it can find, whether or not that path is safe. The Replit incident is exactly this: the agent had access to production, so a “fix” became a deleted database.An agent’s job changes with every prompt. Each request produces a new plan, touches new files, and may follow an unpredictable path. A morning prompt might only need read access to one module; an afternoon prompt might need to run migrations. A static role is either too broad to be safe or too narrow to be useful.One request can cross many tools. In a single task, an agent might read a file, run a shell script, call a package manager, and hit an external API. Each step is a chance for privilege escalation. For example, the agent itself may have no cloud access, but if it runs npm install and a package’s post-install script uses the AWS credentials on your machine, that script effectively gives the agent your access.Putting PoLP into practiceWhether you use a CLI coding agent, an IDE assistant, or an automated CI/CD bot, least privilege has to be enforced by the environment, not requested in the system prompt. An instruction like “please don’t delete anything” is a suggestion. A sandbox is a guarantee. Lemkin had told the Replit agent not to make changes; the instruction didn’t stop it.Run inside ephemeral sandboxes. Run coding agents in isolated containers, microVMs, or devcontainers, not directly on your host OS. If the agent runs rm -rf on the wrong folder, it destroys a throwaway container, not your laptop.Require human approval for risky actions. Separate low-risk read actions from high-risk write, delete, and network actions. Reading files and running tests can proceed freely; installing a new dependency, changing system configuration, or running an arbitrary shell script waits for a person to click Approve.Give each agent its own non-human identity (NHI). Each agent should have its own identity and scoped token instead of acting under your personal account. As Varonis notes, separate identities keep audit trails intact. When the Git log shows review-agent-bot instead of your name, you always know what the agent did and what you did.Use just-in-time (JIT) scoped tokens. Issue credentials when a workflow starts and revoke them automatically when it ends. A token that expires in 30 minutes is worth far less to an attacker than one stored in a .env file for a year.Prevent privilege escalation between agents. When an orchestrator agent hands subtasks to specialized sub-agents, no sub-agent should get more authority than its parent. For example, a code-review agent should have read-only access, even if it talks to a deployment agent that can push to production.2. Network Egress ControlsRemember the genie that was told, through a comment buried in a library, to send your API keys somewhere else? Sandboxing protects your machine and least privilege limits what the agent can touch. Neither one stops the agent from sending out what it can already see. An injected instruction doesn’t need root access. It only needs the agent to make one outbound request, such as a curl to an attacker’s server with your keys in the URL.Egress controls close that door. Even if the agent is tricked, the data has nowhere to go.Default-deny outbound traffic. Allow only the domains the task needs, such as your package registry, your Git host, and internal APIs. Everything else is blocked.Route traffic through a proxy that logs every request, so you can see what the agent contacted and when. A call to paste-bin-mirror.xyz in the middle of a refactoring task should stand out immediately.Block cloud metadata endpoints (such as 169.254.169.254) so a sandboxed agent running on a cloud VM can’t collect the instance’s credentials and send them out.3. Secret ProtectionAgents read everything in their context. If a secret is visible, assume it can leak into a commit, a log, or a prompt sent to a model provider.Keep secrets out of the agent’s workspace. Exclude .env files, key stores, and credential files with ignore rules the agent can’t override.Scan every agent-generated commit for hardcoded keys and tokens before it leaves the sandbox. Agents often “helpfully” paste a working key into a config file to get a test passing.Redact secrets from logs and transcripts, since agent session histories are often stored and shared.Use a secrets broker instead of raw values. The agent asks a vault or broker to perform an action (“call the payments API”), and the broker injects the credential at runtime. The agent never sees the actual key, so it can’t leak it.Give the agent placeholder or dummy credentials. In development sandboxes, use fake keys that look real but only work against mock services. If they leak, nothing is exposed.Strip credentials from the shell environment. Run the agent’s shell without inherited variables like AWS_SECRET_ACCESS_KEY or GITHUB_TOKEN, so a simple env or printenv command reveals nothing.Block access to credential stores on the host. Deny reads on paths like ~/.aws/credentials, ~/.ssh/, ~/.kube/config, ~/.docker/config.json, and browser profile folders, even if the agent “just wants to check the config.”Rotate after every exposure, not only every breach. If a secret appears in an agent’s context, logs, or a diff, even briefly, treat it as compromised and rotate it. Automate this so rotation is cheap enough to do every time.Watch for secrets in less obvious places. Agents can leak keys through error messages, stack traces, test fixtures, sample config files, and code comments, not only source code. Point your scanners at all of them.4. Mandatory Review GatesAn agent should open pull requests, not push to protected branches. Treat the agent as a fast junior developer whose work always gets reviewed.Use branch protection so agent identities can’t merge to main or deploy to production.Label agent-authored PRs so reviewers know to read them more carefully, especially large diffs that look plausible.Cap the diff size per task. A 3,000-line change produced in two minutes can’t be reviewed. Ask for smaller, focused changes.Require the agent to explain its changes. Every agent PR should include a summary of what changed, why, which files were touched, and what was not done. A missing or vague explanation is a reason to reject the PR.The person who prompted shouldn’t be the only reviewer. The developer who asked for the change already trusts the result. A second human reviewer brings fresh eyes and doesn’t share the prompter’s assumptions.Route sensitive paths to code owners. Changes to authentication, payments, infrastructure-as-code, CI/CD pipelines, or security configuration should automatically require approval from the team that owns that area, however small the change. A one-line edit to a payment webhook URL is exactly the change a prompt injection would make.Flag scope drift. If you asked for a bug fix in the date-formatting module and the PR also touches the login service, the agent went beyond the task. Check that changed files match the original request and flag anything outside it.Use an AI reviewer, but not as the final reviewer. A separate review agent (ideally a different model) can catch obvious problems first, so human reviewers can focus on logic and intent. It supports human approval but never replaces it.Link every PR to its prompt and session log. Reviewers should be able to see the original request and the agent’s tool calls. Reviewing code without knowing what was asked is like reviewing an answer without the question.5. Audit Logging and ObservabilityYou can’t oversee what you can’t see. Every agent session should leave a full, tamper-resistant record.Log every prompt, tool call, file change, command, and network request, tied to the agent’s identity.Make sessions replayable, so after an incident you can see exactly what the agent did and why.Use AI to watch the AI. A separate monitoring model can flag unusual behavior in real time, such as touching files outside the task scope, repeated failed commands, or unexpected network calls. This is the AI-assisted human-in-the-loop tooling described at the start of this article.Store logs where the agent can’t reach them. If the agent can write to its own audit trail, a prompt injection can tell it to erase its tracks. Send logs to an append-only store outside the sandbox, with write access the agent’s identity doesn’t have.Capture the agent’s reasoning, not just its actions. Log the plan the agent made, the context it loaded, and which files or web pages it read before acting. If the agent suddenly changed a webhook URL, the log should show that it had just read a suspicious comment in a third-party library.Use one trace ID per task. A single request can cross the agent, sub-agents, shell commands, package managers, and external APIs. Give each task one trace ID that follows it everywhere, so you can rebuild the full chain instead of piecing together separate logs.Alert on high-risk events, not everything. Nobody reads a million log lines. Define a short list of events that page a human right away: a blocked destructive command, access to a credential path, a call to an unknown domain, a change to CI/CD or auth code, or an approval request that sits unanswered.Build a live session dashboard. Give the human in the loop a real-time view of what each active agent is doing: current task, files touched, commands run, tokens spent, and pending approvals. Oversight works better when it doesn’t require digging through logs.Review agent behavior regularly, not only after incidents. Hold a short weekly or sprint-level review of agent sessions: which approvals were denied, which commands were blocked, where scope drifted. Patterns there show which guardrails need tightening before something goes wrong.ClosingGuardrails don’t make the genie less powerful. They make sure that when it grants your wish, you’re still the one holding the lamp.SourcesAI Incident Database, Incident 1152: Replit agent deletes production data during code freezeVaronis: Least privilege for AI agentsThe Genie Who Granted Me 10,000 Tokens was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.