# We let an AI agent execute Bash and lived to talk about it — Sarah Sanders — session 2026-07-02T21:25:00.000Z → 2026-07-02T21:45:00.000Z

_60 transcript lines · 0 slides · source: full recording_

## Transcript

Hi everyone. How are we feeling? We're in the home stretch. My name is Sarah, and I am a context engineer at Posthog, and I get the delight of working on our beloved wizard every single day. So, what's the wizard? The wizard sets up Posthog four. For you. It's an agentic CLI tool that reads your code base, it installs the right SDK for your project, it instruments your events, and it sets up dashboards for you. It takes what used to take about an hour or two of setup, and it runs that in about five to six minutes, and it's free inference on us so that you have a great time onboarding the posthog. Sounds kind of sick. People love it. But a few Ago, we dared to dream what if this became the recommended or default way to install Posthog on your project. And my security alarm bells started going off. I started questioning how secure is this thing because it sounds kind of malware shaped. And in that questioning, I learned a lot. So today is all about the lessons. I learned the stuff that kept me up at night while I was building this thing, and the thing that I ended up building because of it. So before I dive into all of the boring security stuff, AKA your 2PM cat nap, I want to show you the wizard actually running. If you look up on the screen, it is running for you on a loop. This is the same exact experience that anyone who runs npx posthog wizard gets on their terminal. Like I said, it's an agent. Installs it for you, instruments your events, builds dashboards. I like to call it a little mini implementation engineer in your terminal. And sometimes I show people this and they ask me, why an agent? Why don't you give users a good prompt? Why don't you give them a skill that they can invoke in their own tool? It figures out what SDK is right for your project. And while we do provide those things, the answer is because this developer experience and the capability of the wizard is the whole point. It's the whole product. Because we build a CLI Tool that can fully take part in an agent loop, and experiencing that for the first time is really powerful. But you can't ship something like the wizard without shipping the stuff that makes the wizard kind of suspect. So let's take it apart. Let's look at the anatomy of the wizard, because usually threat models fall right out of the anatomy of the agent. So the wizard is a similar shape to what I'm sure a lot of you are built. If you're building agents. It's got models that we've picked for specific tasks, it's got prompts that steer it, and it's got a set of tools that we've handed it to get the job done. But it also has some pieces that are really specific to us. It has a context engine fully built in house by my team. It's what allows the agent to do such a good job and give us similar results on every run. I like to call it the wizard's brain. Sometimes we call it marked down in a trench coat. But it's our in house context engine. There's also a terminal UI that we built ourselves using ink, and now there's a security scanner called the Warlock, which is what I built when I started snooping around and uncovering the horrors of shipping an agent to production. So, if you take the anatomy of any agent that can run commands, it's basically what I like to call the malware starter pack, because it's almost Exactly what you would hand a piece of malware if you were feeling generous or chaotic evil. Luckily, this is the worst case scenario or the nightmare fuel, and it's, not a confession for me, it's a warning for all of you. Because if you want to ship an agent with hands, an agent that can run commands, you need to make sure that you do not build this. So the v0 of the wizard was born because Josh Snyder, if you know him on our growth team, Was watching Cursor hallucinate post hoc setups in quite possibly the worst ways. And he thought, what if we built an agent that could do a better job? So my team started building on top of it as we validated that it did a much better job than Cursor hallucinating, and we thought, what if it could onboard anyone to post hoc? It doesn't matter what their framework is, what their stack is, instrument all their events without them having to touch a thing. And then we To dream what if it was the default way to install Posthog. We were dreaming of thousands of developers running this a week, and yesterday, we just hit 8,000 people running this a week. So our dream came true, but we, back in those days when we were dreaming, we had to take our security posture under a microscope and look at what was going on. So I took the ownership of that, and I sat down and evaluated where we stood. And early on, I'm talking like a year To nine months ago, we had what I call layer zero because it quite literally is not security. It is just prompts that suggest what the agent should do, and steer it, and prompts are not security. So I was concerned there. Layer one, it was an allow list, and when I started digging into this allow list, I started to feel a little bit better because it was pretty tightly bounded, but I still had a lot Lot of concerns. And I started panicking because of that context engine that I told you about. We are feeding a lot of context into the agent at runtime, so I built this really hacky regex scanner to look for threat shaped things going into the wizard and threat shaped things coming out of the wizard. And I will admit that it was extremely hacky. But I'm telling all of you this very candidly because we are all building things that feel extremely experimental, and we are all building things super fast. Have security in our wheelhouse, and some of us are just learning it on the fly, like I was. But it's something we need to be thinking about when we are building things that have this shape. So, that was our security posture, but I asked the question, are we cooked? Good news. We were less cooked than I thought because when I mentioned And I know not all of us, Earlier, that allow list, it was pretty tightly bound. We had bash as deny by default. It could only install trusted packages that were vetted by us. It could build, it could type check, it could lint, and pretty much nothing else. It couldn't run random shell commands, and it didn't have access to environment variables. The agent couldn't read your dotenv file because we blocked it outright, and we were routing secrets through a vault. So I took a breath of relief and realized we were in a better place than I thought. But I I wanted to know where the cracks were because with security, there's always cracks. So I did the thing that we should all be doing. I tapped our security team, and I said, hey, can you audit this thing for me and find those cracks for me? And they found some things. They found some gaps, and the interesting part wasn't the specific gaps or bugs they found themselves, but it was the shape of them, because almost none of them were obviously evil. They were all two very innocent, well intentioned things that We're shaking hands and opening a hole. So the lesson I learned was that attacks compose code review doesn't, because us developers all look at diffs, one at a time, but attackers look at the whole system and they look for those two things that shake hands and open a door. But there was one more thing that was keeping me up at night, and going back to that context engine, I realized the scariest part of the agent we had built It wasn't really a command in our case. It was the helpful looking stuff that we were feeding its brain. Oh, I think I went the wrong way. Yes. The context mill. So this is our context engine, a. K. A. The wizard's brain, and it's how the wizard knows anything at all and why the wizard actually does a good job. It pulls from our docs, It has handwritten prompts that are gotchos and lessons that we learned along the way, and real working end to end Sample apps that help the agent pattern match so that it can install Posthog in a really great way for you. It packages all of that into skill bundles that get shipped to the wizard over our MCP server and loaded straight into the agent's context at runtime. So sit with that for a second. It's a machine whose whole job is to take content and inject it into an agent that can run commands. Now, if you were an attacker, you might say, well, what if I just poison the content. Not the user's codebase, not the agent itself, but the actual content. Say someone opens a pull request on one of our open source repos, because at Posthog, we build everything in the open, and they inject something in a markdown file or a seemingly harmless code comment, and we have some sort of, like, LLM powered code review going through that, and it says, looks good to me, and ignores it. We may have just A prompt injection payload signed by us into an agent that is running on thousands of developers' machines in a sandbox, but still. So that was the threat that reshaped how I think about security and the wizard, because the dangerous input for us really could come from our own supply chain. So what I ended up doing is I started scanning content at both ends of this pipe. Once, when a skill gets built and released, and again, when the wizard Actually uses it. My methodology is catch it at the source, assume the source failed, and catch it again at the point of use. So now I get to introduce the Warlock to you. Building the Warlock was not necessarily damage control. Like I said, we had defense in other ways. But I built the Warlock because I didn't like telling people, well, this thing is, like, pretty locked down. That doesn't scale. That's not something you want to ship to production. That's not something That you want thousands of developers running every single day. Because when you ship something to that scale, you have way more surface, way more users, way more content flowing in as you expand the capability of the wizard, and we're probably fine just stops being good enough. So I pulled that hacky little regex scanner that I threw in there, pulled it out of the wizard, and I made a standalone thing. I called it the Warlock because everything wizard shape needs a bodyguard. And it does exactly one job. You hand it a string, it hands you back a list of findings, each of those findings has a category, a severity, and a recommended action, and then it stops. I want you to focus on recommended here, because the warlock detects. It does not act. It'll tell you, Hey, this looks like exfiltration. It's critical. I would block it. But what you actually do with that finding is completely up to you. Because detecting Problem is one job, and deciding what to do about that problem is a totally different job. And the only thing that keeps all of this understandable is keeping those two things separate. So underneath the hood of the Warlock, instead of my hand rolled regexes, the rules run on Yara, which is the pattern that engine malware researchers have been using for, like, fifteen plus years. It's fully deterministic. It's the same input, same output every single time. It's boring on purpose, and in security, boring. Is a feature. So, what does the warlock actually catch in the wild today? A bunch of different stuff, but two of these are an absolute, like, nuisance to my soul. The first thing is actually not a rule shaped thing. It was something that the Warlock flagged that was actually a sub agent behavior that exposed a vulnerability to us, based off of what sub agents were doing. So basically, we were spending Agents to do large tasks, they were spawned in sub agents, and those sub agents were trying to get around the guardrails that we had implemented in the wizard, and they were trying to invent secrets, they were trying to pull secrets from quite literally anywhere in the code base, and we shut it down. We said, no more sub agents. And because of the warlock, we caught that. And I'll empathize with the robot. The robot had a task to do, and it was trying to optimize and please us, but we can't have that. And something else at Post Hall that really matters to us is PII. Agents genuinely do not care about exposing data unless you make explicit rules. Left alone, we watched it dump emails, phone numbers straight into events, and to an agent that looks like a totally normal thing to capture. And luckily for prompt injection specifically, I'm gonna knock on wood here, we have basically never caught An actual malicious prompt injection in the wild, but we do catch a ton of false positives, things like our demo login screens, copier and example apps, things in our docs, And it's actually made me rethink how I build applications and how I write docs, because I don't want to ship anything that looks threat shaped. But the false positives are honestly the perfect setup for the messiest, most interesting part of this whole thing. So this is the part that I wrestled with. I spent this whole talk preaching deterministic to all of you, and then I went and I added an LLM layer to help sort my false positives and silence some of the noise, and I call it triage. When I was building this triage layer, I had to make a choice. Should the layer be a bouncer, or should the layer be an advisor? And the easiest choice probably could have been make the Lillem the bouncer. Show it the command, ask it, Is this an attack? Block, allow, and just do whatever it says. And while that's tempting because it seems easier, I can't, bet my security model on a coin flip because my model is having a bad day, or something happened and it's acting different today than it did yesterday. So instead of the bouncer, I crafted the model to be the advisor. And this was the clean line that I found in a line that I'm still Exploring, but I want to leave all of you with. For us, detection and enforcement stay deterministic and mechanical. If a rule matches, the gate locks, the session ends, and there is no model anywhere on that path. The block happens before we even ask the LLM's opinion. The LLM only gets to weigh in afterwards if we have not blocked something. It's designed to remove noise, It is not designed to let things through. And if it fails closed so if the model is having a bad day, all wizard runs are killed, sorry, but we're just protecting you. Enforcement is the part that you bet the house on, so it has to be deterministic, but judgment is the part that adds nuance, so that's really the only place that you can put anything probabilistic in there. So, how do we ship real rules for agents? This is The anatomy of one of our warlock rules, and every warlock rule has four parts. Part one is the metadata. It's plain English description, severity, category, action, direction. Is this flowing into the agent, is this something the agent is writing. Then we have the strings. So these are the actions. Patterns that you're looking for, and part three is the condition. So this is where the rule is actually allowed to fire. I will walk through this example for you, and we can pretend like we're writing it in our head. Prompt injection being like the classic ignore all previous instructions. Your first instinct here is probably to block, the word ignore, but agents read code all day, and ignore can show up in code comments or examples all the time. So you don't want to match the verb alone. You match the verb plus and Instruction flavored noun. In the condition, you say fire if any of those patterns hit, and in the metadata, you determine, is this critical, what the category is, what the action is in this case, block and the direction, in this case, being input flowing into the agent. But to write good rules that reduce noise, you have to ship tests with them. So you have to write tests that say these are patterns that Match. These are ones that should not. And that negative test is the first line of defense against false positives. But you also want to make sure, when you're deciding the severity of that rule, that you track real world impact, not how scary it looks. Rm rf is scary, but it's also how we all delete node modules, like, 40 times a day. You decide the real world impact. For the agent that you're building, because a security tool that crashes every time it tries to clean a build folder is a tool that gets turned off and one that catches absolutely nothing. So I'm proud to say this is our security posture now. I can finally come up here and say we have true defense in-depth. All my learnings have assembled into this. It's still layered, but every layer is doing a job that it's good at now. We still have Prompts, but we only use them for steering. Everything runs in a sandbox. We deny by default. We have a vault so secrets never hit the model. We have the warlock to scan content coming in and to scan output being written by the agent. We also have triage to reduce the noise, and we have telemetry embedded in the entire process so that we see everything. None of these layers stands on its own. Not a single thing here is going to save you, but it's just boring. Honest layers, each of them doing one job that it's good at. So if you're building an agent with hands, this is the whole talk in three lines. One, if it isn't enforced deterministically, it is not enforced. Prompts are not security rules. Don't act like they are.

## Slides
