r/PiCodingAgent • • 13d ago

Question How do you handle restricting what PI is allowed to do?

My goal is to reduce what AI can do through PI that might be destructive or not wanted. It is not very likely but it is a huge issue if it happens even once. Core concern worked on now was bash tool call commands.

My initial approach with PI's help was extension that more or less did this:

  1. If used tool is bash
  2. Check all commands called by tool
  3. I have 3 lists of commands DENY, ASK, ALLOW, if command not in any list ask user to classify it [extension overrides supplementing file that saves my choice]
  4. If any are in DENY list reject command with info [info for agent to make it understand its intended and lessen his attempts at working around restriction]
  5. If any are in ASK list prompt user for confirmation [or reject with info if in headless mode]
  6. If all are in ALLOW list execute command

Worked pretty nice at the start but the commands PI cooked up are fairly complex and I was unable to make it write a parser that would correctly identify what is a command and what is not, for example first iteration was using:

.split(/&&|\|\||[;|]\s*|\n/)

Which for example incorrectly tagged this as not classified command:

ls | grep "option1|option2"

And it suggested that "option2" is a command and asked for its classification.

I have iterated over it a bit but i was unable to arrive at a foolproof solution.

Additionally on review agent pointed out to me that since AI is very "goal focused" it might try to engineer around it by for example modifying extension's ALLOW list and executing what it wanted.

Simplest solution was to make this file root:root owned 644 and abandon dynamic updates by extension. Any commands not yet in it would have to be added by me manually as root but that's not the end of the world. And since file is root owned edit tool can't mess with it either.

I could almost live with it if my parser for commands was perfect but its very far from it. And I am not sure if i can arrive at anything good enough for use.

Did anyone have similar issues? How did you approach solving them? Even any ready made extensions solving this problem can be a valid consideration.

Or is the only reliable way to achieve some sort of safety sandboxing it?

If it is of any significance I am using it mostly with locally hosted AI, Qwen3.8 Q3_S shoved into 16GB vram, with llama.cpp as inference engine [rocm + hip build]. PI as harness works really well due to how tiny and lightweight it is and system prompt is small as well, lets me make better use of the limited context I can get ~90-100k tokens.

----------------------------------------------------

Edit:

I got more answers than I expected. Big thank you to everyone who offered their time and knowledge.

In the end I decided to go with Docker Sandboxes.

I don't absolutely need that level of isolation, but its the most convenient one and gives relative peace of mind:

  • File system isolation restricts execution to a single mounted directory
  • Detailed network configuration enforces granular traffic rules
  • Internal docker provides a self-contained runtime environment for safe containerized builds

My only issues were documentation being a bit hard to read and understand and PI not being included in sample kits - needed custom shell kit. But after a few days of mingling with PI I knew enough about it to pull it off.

Bubble wrap also seems like a great idea and is a lot more lightweight (admittedly docker sandboxes are really reasonable for a full environment isolation). Will try it out over the next days as it seems like more convenient daily driver.

10 Upvotes

37 comments sorted by

22

u/pilibitti 13d ago

you need a vm or better: an os kernel layer sandbox. lots of tools for it. hardcoding rules for bash etc. will never work. model will just run a programming language (node, python etc.) and write the code to delete your files from there if bash fails and it is determined. on mac I use agent-safehouse which works very well. since it is kernel enforced, pi and anything pi launches is bound by the sandbox rules which is not something you'll get by coding rules to vet commands. I know people use similar tools for windows / linux but don't know the names of them. none of this is optional.

8

u/bankinu 12d ago

Bwrap if you want to sandbox.

But I'm not sure what you are doing there. If you really want a permission system, use pi permission system by @gotgenes.

12

u/StickyThwomp 13d ago edited 13d ago

Nono.sh 

Edit: elaborating a bit. Nono is a sandboxing utility that lets you set up profiles for what a process can and cannot access, deny by default for most things iirc. It's saved my ass many times from an agent failing proper syntax in a bash execution. I highly recommend it, or something like it, instead of letting an agent raw dog your PC. 

For me, it's "win" over something like executing in a VM or docker container is ease of use. It's executed as a simple command wrapper, and doesn't require heavy infrastructure. If I want the agent to have temporary free reign of my PC, I can do so, if I want it to work offline and only in it's folder, I can do so, just by executing with a different profile.

5

u/LandlockedPirate 13d ago
  • 1 I run it in a devcontainer not my host os
  • 2 I use bubble wrap to protect sensitive files etc

4

u/Itchy_Ad_2562 13d ago

I’ve written an agent orchestrator that runs PI agents in container. It’s basically only the orchestrator, and correctly set up the agents can do all kind of things like chatting, software development, creating documents etc.

As the agents are pretty nicely scoped and monitored I can run them without much observation on my part.

https://github.com/ainsel-project/ainsel

1

u/FormalAd7367 13d ago

Sounds cool. i’m on the train, so the agent can communicate with other pi agent?

1

u/Itchy_Ad_2562 12d ago edited 12d ago

This was a difficult decision but the platform itself does not allow it at the moment. I tried a few things out but for the user invisible agent to agent communication has many disadvantages when the agents should work on a task together.

I assume agent to agent communication works very well when one agent just retrieves information from another agent, or when one agent does something simple for another agent e.g creating a ressource.

For my use cases it was often a back and forth between agents. E.g one agent defining what should be done, one agent doing the actual task and a third agent checking whether the task was done right. Having these conversations invisible for the user makes it difficult to track what was actually done and why.

So instead of agent to agent communication I’ve resolved it by configuration. E.g. one agent can leave a comment/message on a platform, which then triggers another agent.

Like this I can follow the chain of thoughts when I’m back on my PC. And I like that the agents are behaving mostly like humans. So I stay in my comfort zone :-)

Edit: one more thing. Currently I’m developing a Forgejo and GitHub Plug-In for SW developers. They will make it a lot easier to get started. Will probably be there in 2-3 weeks :-)

1

u/dennisler 12d ago

How do you handle softwaredevelopment, not talking about a websites, but rather fat clients. If you have the agent running in a container how can they spin up an application and screenshot, navigate etc. ?

1

u/Itchy_Ad_2562 12d ago

While I provide a PI base image within the repo, the actual container image the agents run with is configurable. This is necessary because also for software development there is not a “one size fits all” solution.

For frontend development I can provide my agents with an image that has all the development tools, so that they can actually “see” what they are doing. They can even attach the screenshots to their PRs once they are done.

But this approach also has its limits. There is only so much an agent can do without human interaction. Very complex tasks (around epic level) are still prepared or fully done by me on the CLI together with a frontier model. The containers themselves are running with smaller models on my spark.

4

u/Extra_Loquat_7667 13d ago

You should use a sandbox system.
Intercepting bash commands cannot address every scenario.
For instance, it cannot prevent an agent from writing a Python script designed to delete your files and then executing it,because, from the perspective of bash commands, such an action appears to be a normal operation.

1

u/subspectral 12d ago

Why you didn’t search for 3s and find one of the several excellent Pi permissions extensions is a mystery.

The Docker sandbox is a good idea, too. But why post here without searching, first? You can find permission extensions directly from pi.dev.

1

u/lonycowz 11d ago

I did see the pi-permissions, actually the first thing i saw. But its basically similar to my attempt at reigning in what PI can do with extension. I did not want to cut out bash tool completely it offers way to much to agent to block it for a lot of cases. And using pi-permissions extensions would be similar - only as good as i can get with predicting what ai can spawn in bash [I am definitely losing this battle] or accept a few obviously ok and get stuck in accepting every 5 sec hell. Hence i started looking around for alternatives.

I saw the default 4 suggestions from pi docs:
- Plain docker
- Docker sandboxes
- OpenShell
- Gondolin extension

And maaany more community solutions. And sadly I have to admit checking everything in depth and comparing them alone is a bit beyond my capabilities [can throw ai at the problem but I like to have at least passable level of understanding tools I use]. And ended up with this post.

3

u/async-monkey 13d ago

Immutable OS (FCOS) + rootless podman containers for each agent. Probably overkill, but it lets me update access once and up-front instead of every time

3

u/randomgenericbot 13d ago

pi-gondolin as sandbox (so only read/write in the currently mounted folder) with a custom image.

that custom alpine image has removed apk (so no package install at runtime), and instead gets all the single tools the agent needs in its daily work (git, rg, and other things) as well as a couple of additional read only mounts, and *.sub.myhost.com "whitelist" for http egress, so it can reach services on my nas for data retrieval (kiwix, gitea, nas readonly status, and filtered websearch). gitea holds mirrors for github projects we work with, readonly public repos as well, so can be cloned at will by the agent.

git credentials are only on the host, so the agent can commit, fetch, even delete locally, but never push.

so the only damage that can ever occur is the fresh work within the sandbox folder since my last manual push gets lost.

by now I've also added a "host-bash" extension, that grants an host side bash tool call, which requires my approval so the agent can still - if it convinces me that it is needed - run a command with user privileges.

so I guess the biggest security issue in that loop now is me.

3

u/lukyjay 11d ago

I have an ansible script that prepares a debian VM which is basically a sandbox. The pi service runs as a separate user and has permissions locked down. This means my pi agents are allowed to do anything they want, given the VM is isolated and the user it runs as is unable to access sudo, my own network (firewall), and everything is immutable

2

u/Direct_While9727 12d ago edited 12d ago

I’m currently testing OS-level sandboxing in my Pi-based harness, Pi Outpost.
It uses the same sandboxing technology as Codex (mxc on Windows, seatbelt on macOS, landstrip or bwrap on Linux).
My goal is to provide an all-in-one Node.js solution that doesn’t require complex setup or the installation of additional third-party software.

I’ve also experimented with pi-permission-system, which takes an interesting approach: it breaks down agent tool calls into individual operations and checks them against permission rules.
Unfortunately, as you’ve discovered, reliably analyzing arbitrary Bash commands is a different story. Shell syntax is simply too complex, and there are too many ways to achieve the same result.
That’s why I believe OS-level sandboxing is ultimately the more robust solution: instead of trying to predict what a command might do, you restrict what the process can actually access or modify.
I’d particularly appreciate feedback from Windows users, as I haven’t been able to test that platform myself yet. If you’re willing to give it a try, I’d be very interested in hearing how it behaves with your setup!

2

u/ryanscio 13d ago

There's a pi-automode plugin, also see Jev as classifier

But tbh these days I stop trying to hand hold agents at all and just run in sbx with no harness-level guardrails in a Debian box

1

u/Relevant-Movie4645 12d ago

Im curious @ using Jev or the new google classifier to rate commands. Wish I had more tokens to spare~!

1

u/fuchelio 12d ago

have pi runs as its own Linux user with no sudo, and a per-agent permission file lists exactly which folders it can read and write and which commands it may launch. Everything else, including my home directory and secrets, is simply unreachable to that account.

1

u/TallDuck9 12d ago

i had it copy codex policy modes, and implemented it around that

1

u/jumski 12d ago

I created simple opinionated wrapper on top or bubble wrap on Linux and I rely heavily on it. It's not perfect but good enough for my needs.

Dint have anything for http traffic yet, but I keep an eye on nono.sh

1

u/Parliament5 12d ago

I'm currently solely using Docker sbx. Knew I had to sandbox on my first run of pi when it started reading everything in my /home directory. I haven't ran into any issues so far.

1

u/Chirimorin 2d ago

Sandboxing is the way. The non-sandbox solutions are basically one of three categories, all fundamentally flawed:

  • No dangerous tools available: Hello crippled agent who can't remove old/temp files or even compile/run its own code for testing.
  • Tool calls check for danger and block if it's found: Cripples the agent slightly less, but now it can attempt to bypass your security. No bash rm? What about creating an empty file to overwrite the other file? What about doing it through one of the many programming languages out there? Does your dangerous command detection really catch everything?
  • Tool calls require user-approval: works for the first 10 tool calls, but by tool call 100 you're either clicking accept without even checking or you've already clicked "always allow". That's not security, it's theatre and the biggest benefit is having a human to blame when the agent fucks up.

A sandbox is the best of all worlds here: fully capable agent, no annoying approval popups, the damage the agent can do is inherently limited to its own sandbox.

I don't absolutely need that level of isolation

Counterpoint: you do. Everyone running agents with any kind of write access does.

My only issues were documentation being a bit hard to read and understand and PI not being included in sample kits - needed custom shell kit.

An pi kit is available: https://hub.docker.com/r/sbx/pi-kit (image: docker.io/sbx/pi-image:latest), but a custom shell kit with a pi install command works just as well.

0

u/Corythebeast7 13d ago

I have an extension that simply applies a regex to each bash command and if it matches it spins up an approver agent. That approver agent gets the directory the agent is operating in, list of files, and then approves, denies, or asks the user.

0

u/Slight-Living-8098 13d ago

I just use the pi-permission-system extension.

0

u/TemporaryUser10 13d ago

Run it as SysAdmin on my Linux box, know Linux so that I can prevent or undo major mess ups, never give it sudo

0

u/fingerthief 13d ago edited 13d ago

If you want to try to stop the huge variation of commands agents can come up with you need a classifer of some kind. When Jev was released I thought that would be a great use case, and it is indeed passable but not really thorough at all and quite noisy.

I ended up spending some time training a tiny command classifier model myself over a period of time and was able to outperform all other classifiers I could find overall.

If you want the honest truth, no classifier that exist will protect you from all sneaky or malicious commands. There is a fine balance between asking for real risky commands and spamming approval prompts. It doesn't take many false positives for a user (or me) to just disable it entirely.

I've done the best I can with the available training data and even generating synthetic data from red team swarms attacking the guard. It still has issues though with certain false positive areas. Hopefully I can make
it better eventually.

The true answer is a proper sandbox.

Extension - https://www.npmjs.com/package/specpi-lancet-guard
Base Repo - https://github.com/TannerMidd/LANCET-model
Github Pages - https://tannermidd.github.io/LANCET-model/
Hugging Face Demo (try in browser) -https://huggingface.co/spaces/fingerthief/lancet-nano

15

u/crusaderky 13d ago

Bwrap sandbox. Anything less feels suicidal.

1

u/v_0009 12d ago

1

u/skariel 11d ago

How does terrarium compares to nono?

1

u/v_0009 11d ago

Nono is host level sanboxing. Like bwrap. Terrarium wraps agents in hardware VM. You can run an agent with nono configuration in the terrarium. Terra is then the hard can of what it can do on the host machine (if anything) and nono provides granular control.

1

u/skariel 11d ago

nono is a VM

1

u/v_0009 11d ago

Which nono? This https://github.com/nolabs-ai/nono?

Edit: That does not use VMs. Its kernel level sandboxing afaik.

2

u/skariel 11d ago

you are correct! I confused nono w/ smolvm. In my original question I wanted to ask regarding smolvm

2

u/v_0009 11d ago

Ah yes. Smolvm is cool. I actually wanted to use smolvm initially. I went on with terrarium because smolvm targets broader use cases with more flexibility, more code to audit. It forks libkrun. There is lot of code it tries to provide. Terrarium on the other hand is fixed kernel. Fixed set of devices. As minimal as it can be. Based in rustvmm instead of libkrun but most of VM code is in terrarium itself.

1

u/v_0009 10d ago

Oh and one more thing. SmolVM bases on libkrun which requires host side sandboxing because:

The VM boundary does not restrict host resources exposed through devices.

That's actually the main reason, why I created terra. Terra assume the guest is hostile by default and on top of host side sandboxing - sandboxes each of devices in WASM.