In "auto" mode, the big players all ask a black box classifier model if commands being run by the agent should be allowed. It's super handy to have this capability for local work as well, and I also used building it as an excuse to get some experience training a small (but effective) encoder model on a domain with a limited vocabulary, and have the whole shebang run by Neon with my guidance (it's a great model, but can still spin out in strange ways).
The first version was trained from scratch using a corpus generated by Neon with a "shell simulation environment" I asked for inspired by fuzzing techniques. It worked well on the held-out set from the corpus, but then didn't generalize well to similar but different commands it hadn't ever seen.
The second version used https://huggingface.co/jhu-clsp/ettin-encoder-17m as a base, and then ran the generated corpus as a fine-tuning pass, which got much better results (and added some awareness of non-shell code which helps spots dangerous things in executed Python or JS scripts).
All of the pipeline for generating data, training, and fine-tuning is included in the repo.
It tries to be clever about doing things like expanding variables, taking ambient shell context into account, looking into scripts that are being executed, seeing if something is obfuscated using things like base64, etc. It also supports a large group of shell syntaxes (parses and converts them to a common IR before processing further).
However (and hopefully this is somewhat obvious), there's only so much a tool like this can do to detect unsafe behavior (what if the script being executed downloads new code to execute?) so be safe and run your stuff in a sandbox (there are a million providers out there at this point) when unsure about safety.
Have fun!