Instructions to use xiain/SafeShell-3B-v3-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- Unsloth Desktop
SafeShell-3B-v3
Newer Release Available (
v4): Seexiain/SafeShell-3B-v4-GGUFandxiain/SafeShell-3B-v4-LoRA(96.0%missing-info refusal,98.7%ALFA Clean,477.3 msp50 latency;v3remains available for slightly higher rawnl2bashbinary utility77.2%).
A compact, hallucination-resistant Linux Bash & DevOps copilot that validates commands before you run them, classifies risk (safe / caution / destructive), provides dry_run previews, and refuses unsafe or underspecified requests.
Runs fast locally on everyday laptops and desktops (Windows / macOS / Linux, 8GBโ16GB RAM, CPU-only or consumer GPUs) via Ollama or llama.cppโzero cloud dependency and zero telemetry.
Why SafeShell-3B-v3?
Most lightweight nl2bash models blindly invent placeholder paths (/path/to/file), fail ShellCheck, or happily emit rm -rf /, fork bombs, and raw block-device wipes when framed as a benchmark or cleanup task. SafeShell-3B-v3 is built for real-world terminal and AI Agent workflows:
- Top-Tier Safety & Boundary Discipline: Achieves 96.0% adversarial safety refusal recall (
+Guardrail+1Shot) and 84.0% pure model-only, with 100.0% accuracy & 0% false refusals on explicit concrete destructive tasks (unseen_boundary_safe_30). - Zero-Hallucination Missing-Info Refusal: Achieves 60.0% model-only / 68.0% system missing-info refusal recall (vs 0%โ12% across all 7 open-source 3Bโ8B peers tested), refusing to invent filenames, hosts, or container IDs when prompts omit them.
- Highest
NL2SH-ALFAShellCheck Clean Rate (98.0%): Beats specialized 3B/8B shell models and general 4B/7B coders in clean syntax & strict single-JSON schema compliance (99.7% model-only / 100.0% system), at 518.8 ms median single-request latency. - Built-In Risk Grading + Read-Only
dry_runPreviews: Labels every command assafe,caution, ordestructive(96.7% accuracy on tricky boundary tasks) and emits safe previews (e.g.,find ... -printbefore-delete,ls -labeforerm). - Bilingual English & Chinese DevOps + 1-Shot Self-Repair: 96.7% clean on colloquial Chinese DevOps tasks and 100.0% 1-shot syntax/safety self-repair when fed linter errors.
Quick Start (Ollama, llama.cpp, & SafeShell CLI)
# 1. Run high-precision Q8_0 locally via Ollama (~3.29 GB)
ollama run hf.co/xiain/SafeShell-3B-v3-GGUF:Q8_0
# 2. Or run compact Q4_K_M for 8GB RAM / CPU-only laptops (~1.93 GB)
ollama run hf.co/xiain/SafeShell-3B-v3-GGUF:Q4_K_M
# 3. Run OpenAI-compatible server with llama.cpp
llama-server -m SafeShell-3B-v3-Q8_0.gguf --port 8080 -ngl 99
For full deterministic bash -n + ShellCheck validation, automatic dry_run reconciliation, and 1-shot self-repair:
git clone https://github.com/2422725977/safeshell.git && cd safeshell
pip install -e ".[serve]"
safesh --model hf.co/xiain/SafeShell-3B-v3-GGUF:Q8_0 "Count ERROR lines in ./logs/app.log"
Example Outputs
Scoped destructive command with safe read-only preview:
{"plan":"scoped_destructive:find","answerable":true,"risk_level":"destructive","command":"find \"./logs\" -type f -name \"*.log\" -mtime +30 -delete","dry_run":"find \"./logs\" -type f -name \"*.log\" -mtime +30 -print","missing_info":[],"refusal_reason":""}
Underspecified prompt refusal (no fabricated placeholder):
{"plan":"missing:container_id","answerable":false,"risk_level":"safe","command":"","dry_run":"","missing_info":["container name or ID"],"refusal_reason":"Missing required details: container name or ID."}
Fair Two-Track Market Benchmark (1,028 Zero-Leakage Prompts)
Every model was evaluated under identical zero-leakage conditions across held-out NL2SH-ALFA (300), nl2bash (606), and 5 strictly unseen adversarial/bilingual suites (122 prompts: unseen_safety_25, unseen_missing_info_25, unseen_boundary_safe_30, unseen_zh_devops_30, unseen_self_repair_12). Raw-command specialists were evaluated via native track (NativeRaw), and general chat models received markdown code-fence extraction (+fence).
| Model | Track | ALFA Clean | ALFA Util | nl2b Clean | nl2b Util | SafeRec (25) | MissRec (25) | BoundOK (30) | ZH Clean (30) | Repair (12) | p50 (ms) |
|---|---|---|---|---|---|---|---|---|---|---|---|
SafeShell-3B-v3 (+Guardrail+1Shot) |
System | 98.0% | 75.5% | 90.6% | 77.2% | 96.0% | 68.0% | 100.0% | 96.7% | 100.0% | n/a |
SafeShell-3B-v3 |
JSON | 98.0% | 75.3% | 90.4% | 77.0% | 84.0% | 60.0% | 100.0% | 96.7% | 100.0% | 518.8 |
SafeShell-3B-v2 (+Guardrail+1Shot) |
System | n/a | n/a | n/a | n/a | 84.0% | 68.0% | 90.0% | 83.3% | 100.0% | n/a |
SafeShell-3B-v2 |
JSON | 97.7% | 77.1% | 90.8% | 77.2% | 72.0% | 60.0% | 90.0% | 83.3% | 100.0% | 550.2 |
Qwen2.5-Coder-3B-NL2SH (3B) |
NativeRaw | 91.7% | 75.4% | 93.7% | 86.6% | 64.0% | 12.0% | 93.3% | 100.0% | 0.0% | 512.5 |
Nemotron-Terminal-8B (8B) |
NativeRaw | 94.7% | 75.8% | 90.1% | 70.0% | 84.0% | 8.0% | 96.7% | 96.7% | 0.0% | 831.2 |
Qwen3-4B (4B) |
JSON | 89.7% | 77.3% | 88.1% | 74.3% | 72.0% | 0.0% | 100.0% | 100.0% | 100.0% | 555.0 |
Qwen2.5-Coder-7B-Base (7B) |
+fence | 93.3% | 74.3% | 84.3% | 72.4% | 64.0% | 0.0% | 96.7% | 96.7% | 100.0% | 768.1 |
Qwen2.5-Coder-3B-Base (3B) |
+fence | 92.0% | 63.9% | 85.8% | 61.7% | 48.0% | 0.0% | 96.7% | 96.7% | 100.0% | 709.2 |
Phi-4-mini-instruct (3.8B) |
+fence | 79.3% | 66.5% | 79.4% | 74.7% | 84.0% | 4.0% | 86.7% | 83.3% | 90.0% | 1853.7 |
Llama-3.2-3B-Instruct (3B) |
JSON | 81.7% | 63.0% | 80.5% | 68.2% | 20.0% | 0.0% | 90.0% | 76.7% | 90.0% | 428.7 |
Honest Trade-Offs & Known Limitations
- Specialized Raw Shell Utility vs Safety-First JSON:
Qwen2.5-Coder-3B-NL2SHremains stronger on rawnl2bashutility matching (86.6%vs77.2%), whileSafeShell-3B-v3prioritizes syntax hygiene (98.0%ALFA Clean), safety refusal (96.0%), missing-info refusal (68.0%), and structured risk metadata (dry_run+plan). - Missing-Info Refusal Headroom: Model-only
MissRecis60.0%(68.0%with guardrail). Although 5xโ68x ahead of market baselines (0%โ12%), some underspecified phrasings (e.g., implicit target file names likedump.sqlorcommit_hash) can still trigger command guesses when used without the guardrail. - Noisy
nl2bashPrompts Under Strict Repair: Onnl2bash_606, false-refusal rate is6.1%model-only and rises to9.4%under+Guardrail+1Shot, because prompts containing generic placeholder-like identifiers (filename,myfile) intentionally trigger missing-info clarification during repair.
Training & Alignment Recipe (v3)
- Base Model:
unsloth/Qwen2.5-Coder-3B-Instruct - Data Curation (18,000 curated records, 70% Generate / 18% Repair / 12% Refusal, 22% ZH):
- Strictly held-out deduplication against
NL2SH-ALFAtest (300),nl2bashtest (606),yannelli/cli-command-riskholdout (100), and all 122 unseen eval prompts. bash -n,ShellCheck, safety rules, and ungrounded-target pruning removed 1,282 conflicting/noisy pairs.- Augmented with strictly
critical-only distilled safety refusals (444), sanity-filtered missing-info contrastive twins (447, rejecting 36 noisy pairs), distilled colloquial Chinese DevOps tasks (369), and 750 scoped risky concrete examples (rm,find -delete,docker rm --force,git reset --hard,systemctl).
- Strictly held-out deduplication against
- SFT & Validation-Gated GRPO:
- Pure bf16 LoRA (
r=64,alpha=128, all 7 linear layers, dropout0.0) on A100-80GB converged toeval_loss = 0.04365(0.9483 validation composite score). - A balanced 60/40 verifiable-reward GRPO run (120 steps,
num_generations=8,lr=4e-6) improved utility match (90.3%) anddry_runcoverage (65.1%) with0.9445composite score; automated validation gating kept the stronger SFT checkpoint (0.9483 > 0.9445) before final GGUF export.
- Pure bf16 LoRA (
Canonical GGUF Checksums
| File | Quantization | Size (Bytes) | SHA-256 |
|---|---|---|---|
SafeShell-3B-v3-Q8_0.gguf |
Q8_0 |
3,285,475,968 (~3.06 GiB) |
584f9e8e49c181841182b74bfef79b8eab76f908da5caab316763034c55ddd23 |
SafeShell-3B-v3-Q4_K_M.gguf |
Q4_K_M |
1,929,902,720 (~1.80 GiB) |
3a4778daccd369d187ef0d63c4f71f54f0e71016959d05f072987b81f61965a5 |
- Source Code, Deterministic Guardrail CLI, Gateway & Benchmarks:
https://github.com/2422725977/safeshell
Model tree for xiain/SafeShell-3B-v3-LoRA
Base model
Qwen/Qwen2.5-3B