tarsniff: Qwen3-1.7B fine-tuned to spot malicious npm packages

tarsniff checks an npm package for malware before you install it. It reads the package (install scripts first, then entry files, then risky code) and returns how likely it is to be malicious. The model is a LoRA fine-tune of Qwen3-1.7B, shipped as a 1.0 GB 4-bit GGUF that runs locally in Ollama: no cloud, no API key.

Quick start

# 1. get the model into Ollama
ollama pull hf.co/mohibovais79/tarsniff:Q4_K_M
ollama cp hf.co/mohibovais79/tarsniff:Q4_K_M tarsniff

# 2. install the CLI (Python 3.10+)
pip install git+https://github.com/mohibovais79/tarsniff

# 3. scan before you install
tarsniff scan lodash
tarsniff scan some-package@1.2.3 && npm install some-package@1.2.3

Or download tarsniff-q4_k_m.gguf and Modelfile from this repo and run ollama create tarsniff -f Modelfile.

The CLI downloads the package tarball, checks npm's sha512 checksum, and reads it in memory: nothing is extracted to disk, installed or executed. Exit code 1 means flagged.

Results

All test packages were never seen in training (training malware ends May 2026).

Live npm malware, Nov 2026. Every npm malware report published by OSV from 13 to 27 Nov 2026 whose malicious version was still downloadable from npm (selected before scoring), plus the latest versions of 286 popular npm packages as the safe control:

Malware caught (74) Safe packages flagged (286)
tarsniff 62 (84%) 29 (10%)
GuardDog 3.2.0 (rule-based, score โ‰ฅ 5) 45 (61%) 5 (2%)
Either one 70 (95%) 32

Did fine-tuning help? Same live packages, same prompts, base model vs this fine-tune (packages with code: 73 malicious, 280 safe):

Base Qwen3-1.7B (4-bit) tarsniff
Safe packages wrongly flagged 93% 9%
Malware caught 96% 85%
F1 0.35 0.77
ROC-AUC 0.82 0.95

Example, safe package @csstools/css-tokenizer: the base model answers "isMalicious": true with an invented reason; tarsniff answers {"verdict": "benign"}.

GGUF vs original (MLX) model, 300 held-out packages: F1 0.747 vs 0.750, same verdict on 99.7%.

Speed: about 1 s per package on a Mac mini M4 (16 GB) with Ollama.

Training

Base model Qwen3-1.7B, 4-bit (mlx-community/Qwen3-1.7B-4bit)
Method LoRA, rank 16, scale 20, dropout 0, all layers; loss on the answer only (mask_prompt)
Data 600 packages: 300 malicious (Datadog malicious-software-packages dataset, Janโ€“May 2026), 300 benign npm packages
Input a package digest capped at 1,024 tokens: file list, package.json (name, version, description removed), install-hook files, entry files, then code ranked by risky API use
Output {"verdict": "malicious"} or {"verdict": "benign"}; the score is P(malicious) from the first answer token
Run MLX-LM 0.32.2, 600 steps, batch 1, learning rate 1e-4, Adam, max length 1,200 tokens
Hardware Mac mini M4, 16 GB: 36 minutes, 2.9 GB peak memory
Export LoRA merged into the de-quantized model, converted with llama.cpp to GGUF, quantized to Q4_K_M

Files

File What
tarsniff-q4_k_m.gguf the model, 4-bit, 1.0 GB (Ollama, llama.cpp, LM Studio)
Modelfile ollama create tarsniff -f Modelfile
adapter/adapters.safetensors, adapter/adapter_config.json the LoRA adapter for mlx-community/Qwen3-1.7B-4bit (MLX-LM)

Prompt format

The CLI sends a raw prompt (Qwen chat format, thinking off) and reads the first token's probabilities. System prompt: "You are an npm supply-chain security analyst. Given the contents of an npm package, decide if it is malicious. Respond with JSON only." Use the CLI to get the exact digest format the model was trained on.

Limitations

It reads only the first 1,024 tokens of the digest, so malicious code buried deep inside a large, otherwise legitimate package (for example a hijacked release of a popular library) can be missed. It works best alongside a rule-based scanner such as GuardDog.

License and attribution

Apache-2.0, like the base model Qwen3-1.7B. Malicious training samples come from the Datadog malicious-software-packages dataset (Apache-2.0). Live test reports come from OSV.

Downloads last month
58
MLX
Hardware compatibility
Log In to add your hardware

Quantized

GGUF
Model size
2B params
Architecture
qwen3
Hardware compatibility
Log In to add your hardware

4-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for mohibovais79/tarsniff

Finetuned
Qwen/Qwen3-1.7B
Adapter
(1,124)
this model