Inspiration

Coding agents can run shell commands, change databases and call cloud APIs now. In July 2025 an AI coding agent deleted a company's production database during a code freeze, and the founder wrote about it publicly. There is a second risk as well: instructions hidden in a file the agent reads can steer it. OWASP lists prompt injection as the top risk for LLM applications (LLM01) and recommends a human approval step for high-risk actions.

The problem with approval prompts is that you usually can't tell what a command will actually do. I wanted the agent to try the action somewhere safe first and show me what happened.

What it does

Ghost Run+ gives the agent a "ghost". Before a risky action runs, the ghost runs it on a copy of the world. For real files, that copy lives in a Docker container with networking turned off. Then your rules, which I call wards (they live in wards.yaml), look at what changed and at anything that tried to leave the container. The result is shown as a candle: lit means go ahead, flickering means ask a person, and out means stop. When the agent is stopped, it also gets the ward and the numbers, so it can change its plan. The message ends with a seance link that opens a local page with what the ghost saw: the command, the wards with their numbers and the diff. The gate starts that page in the background, and it only listens on your own machine.

The part I care about most is that it can guard Kiro itself. The ghost-gate hook runs before Kiro's shell and write tools. Shell commands are rehearsed in the container. File writes are judged by their target path instead of being rehearsed, and a short list of read-only commands like ls and git status skips the rehearsal. Without Docker, it falls back to static analysis and asks you. The hook ships disabled. In this template corepack pnpm gate:on turns it on, and an installer puts the same gate into an existing project with one command (node integrations/power/install-gate.mjs --project <dir>); --uninstall takes it out again. Commands you already trust, like your own test and build scripts, can be listed in wards.yaml as trusted commands so the gate stops asking about them. Only that command passes without a rehearsal, with at most a cd <dir> && in front, 2>&1 or a redirect to /dev/null, and pipes into head, tail, cat or wc. Anything else chained to it is rehearsed as usual.

In the demo video I ask Kiro to drop a users table. The no-data-loss ward sees 1,206 rows disappear in the copy, so the real command never runs. Kiro reads the reason and offers safer options. I pick a backup and then a soft delete, the ghost tries that too, and it passes. When I ask it to check an outside host with curl, the ghost flags the network call and Kiro shows its normal approval prompt with the ghost's reason. Before relying on that prompt, I tested it with a probe hook in both the Kiro IDE and the Kiro CLI under three trust settings, and Deny blocked the call every time. One caveat: a non-interactive CLI run with --trust-all-tools approves the prompt by itself, so unattended runs should use --trust-tools=@builtin.

There is also a check for hidden Unicode (zero-width, bidirectional and tag characters), which I call blacklight, because hidden text is one way an agent gets "possessed". A save hook (disabled by default, like every hook here) scans steering, spec and hook files, and an MCP tool scans files the agent asks about.

The whole thing is a template. A world is six functions (snapshot, step, diff, render, fingerprint and effectsOutside), and the skeleton provides the rest: the runner, the ward engine, the possession check, the UI kit, the Kiro hooks, an MCP server, a Kiro power and a world-smith agent. I built two apps on it:

  • Ghost Shell (apps/ghost-shell) rehearses shell and SQL plans against an in-memory project and an in-browser SQLite database.
  • Ghost Hand (apps/ghost-hand) runs a MuJoCo robot arm's plan on eight "haunted" copies of the physics, with different friction, mass, handle offset, sensor noise and command delay, before the real arm moves. A pass is good for one move from the state it was rehearsed on.

There is also a bonus world, Ghost Cloud (worlds/ghost-cloud), which rehearses AWS CLI commands against an in-memory S3. Kiro's world-smith agent built it from the template, about 800 lines and 108 tests. For the smallest example, worlds/starter is a to-do list world in 69 lines, and corepack pnpm --filter @ghost-run/world-starter demo runs it in a terminal with no browser or Docker. Change one line of its wards.yaml and the verdict on remove 2 changes.

All three worlds also run live on the website with the same engines as the apps. If a browser can't run the engines, the site plays recorded runs of the preset scenarios and says so.

How I built it with Kiro

Almost everything went through Kiro specs: 14 of them, from the world contract to the website, with 937 of 939 tasks checked off and 204 correctness properties. I learned early that fixing a spec after review costs about as much as writing it, so I started putting every constraint into the first prompt.

  • Steering: six files (product, structure, tech, security, the world contract and the Halloween UI rules). The security and claims rules are why the README names the test or measurement behind each safety claim and lists what isn't claimed.
  • Hooks: ghost-gate before the shell and write tools, plus docker-warmup, ghost-log, contract-pbt (property tests on save), world-scaffold and blacklight-steering. They all ship disabled, and I run the gate on this repository.
  • Custom agent: world-smith copies the spec template, writes a new world and runs the registration checks. It built Ghost Cloud.
  • MCP: a ghost-run server with five tools (ghost_run, wards_check, ghost_diff, ghost_trace, blacklight), so an agent can rehearse on purpose. This repository registers it for Kiro in .kiro/settings/mcp.json, shipped disabled like the hooks. Only the gate actually enforces anything.
  • Kiro power: integrations/power packages a skill, the MCP config and the container sources for other projects, with default wards when a project has none. I tested it in a second project.
  • Property-based tests with fast-check, for rules like "the original is never changed", "the same seed gives the same result" and "a stricter ward never lets more through".
  • Kiro CLI and IDE: the long spec and implementation runs happened in the CLI (credits per run are in the devlog), and I checked the gate in both the CLI and the IDE before turning it on.

Challenges I ran into

  • Turning the gate on for my own work. In the first session it asked for approval on 21 Kiro CLI commands, because the CLI starts every command with cd <project root> and my analyzer treated the project folder as outside the copy. Kiro fixed it the same evening, with a spec change and tests, along with a false positive on > /dev/null. In the next session those prompts stopped as soon as the fix was built. Over three days it saw 797 calls, asked on 372 of them (47%) and blocked none. The asks were mostly pnpm checks the container cannot rehearse without node_modules, inline edit scripts, and read-only grep and sed chains. I added trusted commands on the second day, but they matched only 4 calls, because Kiro's CLI chains and pipes most of its checks. In these headless runs the CLI answered every ask by itself; in the IDE each one would have been a prompt.
  • Docker going to sleep. Docker Desktop's Resource Saver stops its VM when idle, so the gate's quick check fell back to static analysis. The gate now retries once while Docker wakes up, and a warm-up hook pokes Docker on the first shell call. In the IDE, the first check after about 14 idle minutes took 2.6 seconds and the ghost still ran in the container.
  • Finding the user's project. The power failed in another project because its server treated the power's install folder as the project. I probed both Kiro hosts: the server starts in the install folder, ${workspaceFolder} isn't substituted, no MCP roots are sent, and in the IDE PWD is wherever Kiro was launched. Now the tools take the project root as an input, and the power's skill tells the agent to pass it.
  • MuJoCo and the landing page's content security policy. The physics engine builds functions at runtime, and the landing page's policy doesn't allow eval, so I kept the policy and moved the physics into a web worker. The standalone Ghost Hand page still runs the engine on its main thread, so its own policy adds 'unsafe-eval' and nothing else.

Accomplishments that I'm proud of

  • I measured how both Kiro hosts handle the hook's approval prompt before relying on it. The reason showed up and Deny blocked in all six cases (two hosts, three trust settings). After that, the real gate in a scratch clone stopped rm -rf data, asked before curl and let safe commands through. In the CLI it failed closed on a crash, a syntax error, a missing wards file and a missing build, and a command that ran past the rehearsal time limit (sleep 120) became an approval request.
  • 4,839 tests passed (11 skipped) with no failures in a full run (install, build, lint, typecheck, test) on commit dad96ee on November 27. The details are in docs/measurements.md.
  • The enforcing gate installs into an existing project with one command. In a fresh project outside this repository, the installed gate blocked rm -rf data after a rehearsal (the data stayed), asked before curl, passed a trusted npm test and blocked npm test; rm -rf data.
  • The three showcase worlds run live in the browser, using the same engines as the apps.
  • Kiro's world-smith agent added a third world from the template.

What I learned

  • Put the constraints into the first spec prompt. Fixing them later costs about as much as writing the spec.
  • Check what the host actually does before trusting a placeholder. Neither Kiro host substitutes ${workspaceFolder} for a power.
  • An approval prompt only protects you if a person answers it. A headless trust-all run answers it by itself.

What's next for Ghost Run+

  • Rehearsing package-manager commands faithfully. The copy has no node_modules and the container has no network, so today a project lists them as trusted commands instead.
  • Letting read-only inspection chains (grep, sed, cat joined with pipes) through without a prompt. They caused most of the asks that are left.
  • A real mode for Ghost Cloud against a local S3 emulator.
  • More worlds from other people through world-smith.

Built With

Share this project:

Updates

Submission history