We let an AI agent execute Bash and lived to talk about it — Sarah Sanders, PostHog
AI Engineer · 21 min · 230 sentences · from YouTube's caption track
Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.
- 00:16Hi everyone.
- 00:17How are we feeling?
- 00:18Uh we're in the home stretch.
- 00:21Uh, my name is Sarah and I am a context engineer at Post Hog and I get the delight of working on our beloved wizard every single day.
- 00:31So, what's the wizard?
- 00:33Um, the wizard sets up Post Hog for you.
- 00:36It's an agentic CLI tool that reads your codebase.
- 00:41It installs the right SDK for your project.
- 00:44It instruments your events and it sets up dashboards for you.
- 00:48It takes what used to 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 to Post Hog.
- 01:01Sounds kind of sick.
- 01:03Uh, people love it.
- 01:04But a few months ago, we dared to dream, what if this became the recommended or default way to install Post Hog on your project?
- 01:14And my security alarm bell started going off.
- 01:18Uh, I started questioning how secure is this thing because it sounds kind of malware shaped.
- 01:25Um, and in that questioning, I learned a lot.
- 01:29So 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.
- 01:40So before I dive into all of the boring security stuff, aka your 2pm catnap, I want to show you the wizard actually running.
- 01:49If you look up on the screen, it is running for you on a loop.
- 01:53This is the same exact experience that anyone who runs npx at post hog wizard gets uh on their terminal.
- 02:02Like I said, it's an agent.
- 02:03It figures out what SDK is right for your project.
- 02:05It installs it for you, instruments your events, builds dashboards.
- 02:10I like to call it a little mini implementation engineer in your terminal.
- 02:15And sometimes I show people this and they ask me, why an agent?
- 02:18Why don't you give users a good prompt?
- 02:20Why don't you give them a skill that they can invoke in their own tool?
- 02:24And while we do provide those things, the answer is because this developer experience and the capability of the wizard is the whole point.
- 02:32It's the whole product because we built a CLI tool that can fully take part in an agent loop and experiencing that for the first time is really powerful.
- 02:44But you can't ship something like the wizard without shipping the stuff that makes the wizard kind of suspect.
- 02:52So let's take it apart.
- 02:54Uh let's look at the anatomy of the wizard because usually threat models fall right out of the anatomy of the agent.
- 03:02So the wizard is a similar shape to what I'm sure a lot of you are building if you're building agents.
- 03:07It's got models that we've picked for specific tasks.
- 03:11It'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.
- 03:21It has a context engine fully built inhouse by my team.
- 03:25It's what allows the agent to do such a good job and give us similar results on every run.
- 03:31I like to call it the wizard's brain.
- 03:33Sometimes we call it marked down in a trench coat.
- 03:36Uh but it's our in-house context engine.
- 03:39There's also a terminal uh UI that we built ourselves using ink.
- 03:44And 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.
- 03:56So, 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.
- 04:12Luckily, this is the worst case scenario or the nightmare fuel.
- 04:16And it's uh not a confession for me.
- 04:18It'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.
- 04:29So the V0 of the wizard was born because Josh Snder, if you know him, on our growth team was watching cursor hallucinate postfog setups in quite possibly the worst ways.
- 04:42And he thought, what if we built an agent that could do a better job?
- 04:46So 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 hog it doesn't matter what their framework is what their stack is
- 05:01instrument all their events without them having to touch a thing and then we dared to dream what if it was the default way to install Post hog we were dreaming of thousands of developers running this a week and yesterday we just hit 8,000 people running this a week.
- 05:16So, our dream came true.
- 05:18Um, 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.
- 05:27So, I took the ownership of that and I sat down and evaluated where we stood.
- 05:33And 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.
- 05:42it is just prompts that suggest what the agent should do um and steer it and prompts are not security.
- 05:49So I was concerned there.
- 05:51Uh layer one uh 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.
- 05:59Uh but I still had a lot of concerns and I started panicking because of that context engine that I told you about.
- 06:06We are feeding a lot of context into the agent at runtime.
- 06:10So, I built this really hacky reax scanner to look for um threatshaped things going into the wizard and threat shaped things coming out of the wizard.
- 06:20And I will admit that it was extremely hacky.
- 06:24But 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.
- 06:34And I know not all of us uh have security in our wheelhouse.
- 06:39Um, and some of us are just learning it on the fly like I was.
- 06:43But it's something we need to be thinking about when we are building things that have this shape.
- 06:50So that was our security posture.
- 06:53Uh, but I asked the question, are we cooked?
- 06:56Uh, good news, we were less cooked than I thought because when I mentioned earlier that allow list, it was pretty tightly bound.
- 07:04We had bash as deny by default.
- 07:06It could only install trusted packages that were vetted by us.
- 07:10Um, it could build, it could type check, it could lint, and pretty much nothing else.
- 07:14It couldn't run random shell commands.
- 07:17And it didn't have access to environment variables.
- 07:21Um, the agent couldn't read your uhv file because we blocked it outright and we were rooting secrets through a vault.
- 07:28So, I took a a breath of relief and realized we were in a better place than I thought.
- 07:35But I wanted to know where the cracks were because with security there's always cracks.
- 07:39So I did the thing that we should all be doing.
- 07:42I tapped our security team and I said, "Hey, can you audit this thing for me and find those cracks for me?"
- 07:50And they found some things.
- 07:52They found some gaps.
- 07:53And the interesting part wasn't the specific gaps or bugs they found themselves, but it was the shape of them.
- 07:59Because almost none of them were obviously evil.
- 08:02They were all two very innocent, well-intentioned things that were shaking hands and opening a hole.
- 08:10So, the lesson I learned was that attacks compose code review doesn't because us developers all look at diffs uh 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.
- 08:27But there was one more thing that was keeping me up at night.
- 08:30And going back to that context engine, uh, I realized the scariest part of the agent we had built wasn't really a command in our case.
- 08:38It was the helpful looking stuff that we were feeding its brain.
- 08:44Oh, I think I went the wrong way.
- 08:47Yes, the context mill.
- 08:49Um, so this is our context engine, aka the wizard's brain, and it's how the wizard knows anything at all and why the wizard actually does a good job.
- 08:57It pulls from our docs.
- 08:59It has handwritten prompts that are gotus and lessons that we learned along the way and real working endto-end example apps that help the agent pattern match so that it can install Post Hog in a really great way for you.
- 09:12It package packages all of that into skill bundles that get shipped to the wizard over our MCP server and loaded straight into the agents context at runtime.
- 09:24So sit with that for a second.
- 09:25It's a machine whose whole job is to take content and inject it into an agent that can run commands.
- 09:32Now if you were an attacker, you might say, "Well, what if I just poison the content?
- 09:37not the user's codebase, not the agent itself, but the actual content.
- 09:42Say someone opens a pull request on one of our open source repos because at Post Hog we build everything in the open and they inject something in a markdown file
- 09:53or 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.
- 10:04We may have just shipped a prompt injection payload signed by us into an agent that is running on thousands of developers machines in a sandbox, but still.
- 10:15Um, 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.
- 10:26So what I ended up doing is I started scanning content at both ends of this pipe.
- 10:31Once when a skill gets built and released and again when the wizard actually uses it.
- 10:38My methodology is catch it at the source, assume the source failed and catch it again at the point of use.
- 10:46So now I get to introduce the warlock to you.
- 10:50Building the warlock was not necessarily damage control.
- 10:53Like 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.
- 11:02That doesn't scale.
- 11:03That's not something you want to ship to production.
- 11:05That'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.
- 11:19and we're probably fine just stops being good enough.
- 11:24So, I pulled that hacky little reax scanner that I threw in there, pulled it out of the wizard, and I made a standalone thing.
- 11:31I called it the warlock because everything wizard shape needs a bodyguard.
- 11:36And it does exactly one job.
- 11:39You hand it a string.
- 11:40It hands you back a list of findings.
- 11:42Each of those findings has a category, a severity, and a recommended action.
- 11:47And then it stops.
- 11:49I want you to focus on recommended here because the warlock detects it does not act.
- 11:55It'll tell you, hey, this looks like exfiltration.
- 11:58It's critical.
- 11:58I would block it.
- 12:00But what you actually do with that finding is completely up to you.
- 12:05Because detecting a problem is one job and deciding what to do about that problem is a totally different job.
- 12:10And the only thing that keeps all of this understandable is keeping those two things separate.
- 12:16So underneath the hood of the warlock, instead of my hand rolled reaxes, the rules run on Yara, which is the pattern that engine malware researchers have been using for like 15 plus years.
- 12:28It's fully deterministic.
- 12:29It's the same input, same output every single time.
- 12:32It's boring on purpose.
- 12:34And in security, boring is a feature.
- 12:39So what does the warlock actually catch in the wild today?
- 12:44um a bunch of different stuff, but two of these are an absolute like nuisance to my soul.
- 12:49Uh the first thing is actually not a rule-shaped thing.
- 12:53It was something the uh that the warlock flagged.
- 12:56That was actually a sub aent behavior that exposed a vulnerability to us um based off of what sub agents were doing.
- 13:04Uh so basically we were spinning up agents to do large tasks.
- 13:07They were spawning sub aents and those sub aents were trying to get around the guardrails that we had implemented in the wizard and they were trying to invent secrets.
- 13:17They were trying to pull secrets from quite literally anywhere in the codebase and we shut it down.
- 13:22We said no more sub agents and because of the warlock we caught that.
- 13:28And I'll empathize with the robot.
- 13:29The robot had a task to do and it was trying to optimize and please us.
- 13:33But we can't have that.
- 13:36And something else at Post Hog that really matters to us is PII.
- 13:40Uh agents genuinely do not care about uh exposing data unless you make explicit rules.
- 13:46Uh left alone, we watched it dump emails, phone numbers straight into events.
- 13:52And to an agent, that looks like a totally normal thing to capture.
- 13:58And luckily for prompt injection specifically, I'm going to knock on wood here.
- 14:03Uh we have basically never caught an actual malicious prompt injection in the wild, but we do catch a ton of false positives.
- 14:12Things like our demo login screens, copy on our example apps, things in our docs.
- 14:18And 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 threatshaped.
- 14:28But the false positives are honestly the perfect setup for the messiest, most interesting part of this whole thing.
- 14:37So this is the part that I wrestled with.
- 14:39I spent this whole talk preaching deterministic to all of you.
- 14:43And then I went and I added an LLM layer to help sort my false positives and silence some of the noise.
- 14:50And I call it triage.
- 14:53When I was building this triage layer, I had to make a choice.
- 14:57Should the layer be a bouncer or should the layer be an adviser?
- 15:02And the easiest choice probably could have been make the LLM the bouncer.
- 15:06Show it the command, ask it is this an attack block allow and just do whatever it says.
- 15:14And while that's tempting because it seems easier, I can't uh bet my security model on a coin flip because my model's having a bad day or something happened and it's acting different today than it did yesterday.
- 15:27So instead of the bouncer, I crafted the model to be the adviser.
- 15:33And this was the clean line that I found and a line that I'm still exploring, but I want to leave all of you with.
- 15:39Uh for us, detection and enforcement stay deterministic and mechanical.
- 15:44If a rule matches, the gate locks, the session ends, and there is no model anywhere on that path.
- 15:50The block happens before we even ask the LLM's opinion.
- 15:55The LLM only gets to weigh in afterwards if we have not blocked something.
- 15:59It's designed to remove noise.
- 16:01It is not designed to let things through.
- 16:04And if it fails clos and it fails closed.
- 16:07So if the model is having a bad day, all wizard runs are killed.
- 16:11Sorry, but we're just protecting you.
- 16:15Enforcement is the part that you bet the house on.
- 16:18So it has to be deterministic, but judgment is the part that adds nuance.
- 16:24So that's really the only place that you can put anything probabilistic in there.
- 16:30So, how do we ship real rules for agents?
- 16:35This is the anatomy of one of our warlock rules.
- 16:39And every warlock rule has four parts.
- 16:42Part one is the metadata.
- 16:43It's plain English description, uh, severity, category, action, uh, direction.
- 16:50Is this flowing into the agent?
- 16:52Is this something the agent is writing?
- 16:55Uh then we have the strings.
- 17:00So these are the actual patterns that you're looking for.
- 17:03And part three is the condition.
- 17:06So this is where the rule is actually allowed to fire.
- 17:11I'll walk through this example for you and we can pretend like we're writing it in our head.
- 17:15Prompt injection being like the classic ignore all previous instructions.
- 17:20Your first instinct here is probably to block uh the word ignore, but agents read code all day and ignore can show up in code comments or examples all the time.
- 17:32So you don't want to match the verb alone.
- 17:34You match the verb plus an instruction flavored noun.
- 17:39In the condition, you say fire if any of any of those patterns hit.
- 17:43And in the metadata, you determine is this critical?
- 17:48uh what the category is, what the action is, in this case block, and the direction in this case being input flowing into the agent.
- 17:57But to write good rules that reduce noise, you have to ship tests with them.
- 18:02So you have to write tests that say this are these are patterns that match.
- 18:06These are ones that should not.
- 18:08And that negative test is the first line of defense against false positives.
- 18:14But you also want to make sure when you're deciding the severity of that uh rule that you track real world impact, not how scary it looks.
- 18:25RM-rf is scary, but it's also how we all delete note modules like 40 times a day.
- 18:32You 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.
- 18:48So I'm proud to say this is our security posture now.
- 18:51I can finally come up here and say we have true defense and depth.
- 18:55Um all my learnings have assembled into this.
- 19:00Uh, it's still layered, but every layer is doing a job that it's good at.
- 19:04Now, we still have prompts, but we only use them for steering.
- 19:08Everything runs in a sandbox.
- 19:10We deny by default.
- 19:12We have a vault, so secrets never hit the model.
- 19:15We have the warlock to scan content coming in and to scan output being written by the agent.
- 19:21We also have triage to reduce the noise.
- 19:24And we have telemetry embedded in the entire process so that we see everything.
- 19:29None of these layers stands on its own.
- 19:32Not a single thing here is going to save you.
- 19:34But it's just boring, honest layers.
- 19:37Each of them doing uh one job that it's good at.
- 19:43So if you're building an agent with hands, this is the whole talk in three lines.
- 19:48One, if it isn't enforced uh deterministically, it is not enforced.
- 19:53Prompts are not security rules.
- 19:55Don't act like they are.
- 19:58Uh two, the dangerous input uh isn't just what your user types.
- 20:03It isn't just the commands that you allow it to run.
- 20:05It's everything flowing into the model, including the content that you write yourself.
- 20:10So scan your own supply chain at the source and when the agent invokes it.
- 20:16Three, attacks compose.
- 20:18Code review doesn't.
- 20:20Most of our gaps during our audit were two innocent things shaking hands and opening a door.
- 20:27The wizard, the warlock, and the context mill are all open source.
- 20:31So, come find me downstairs.
- 20:33I'm in the expo hall at our booth, and I'll show you around uh show you what we built, and I want to hear how you guys are securing your agents.
- 20:42Thank you.