r/PiCodingAgent • u/lonycowz • 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:
- If used tool is bash
- Check all commands called by tool
- 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]
- 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]
- If any are in ASK list prompt user for confirmation [or reject with info if in headless mode]
- 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.
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
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
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.
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:
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?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.
Counterpoint: you do. Everyone running agents with any kind of write access does.
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.