---
title: "From single pull requests to full software packages: Detecting malicious code at scale"
description: "Datadog extended BewAIre, its LLM-based malicious code detector, from pull requests to full dependency packages by stacking a cheap filter model in front of an agentic investigation model."
url: "https://swe.quest/articles/from-single-pull-requests-to-full-software-packages-detecting-malicious-code-at-717a58a001a046a1"
canonical: "https://www.datadoghq.com/blog/engineering/scaling-malicious-code-detection/"
source: "Datadog Engineering"
published: "2026-06-02"
difficulty: "medium"
kind: "Case study"
reading_minutes: 12
tags: ["supply-chain-security","threat-detection","ai-agents","llms","cost-optimization"]
---

# From single pull requests to full software packages: Detecting malicious code at scale

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2026-06-02, 12 min read, Case study. Original: [https://www.datadoghq.com/blog/engineering/scaling-malicious-code-detection/](https://www.datadoghq.com/blog/engineering/scaling-malicious-code-detection/)

## Summary

Datadog extended BewAIre, its LLM-based malicious code detector, from pull requests to full dependency packages by stacking a cheap filter model in front of an agentic investigation model. The agent uses GitHub APIs, osv.dev and SCA to check context such as author history and reverted commits. On 690 test diffs the two-stage design raised accuracy from 97.4% to 99.86% by cutting false positives from 17 to 0, and static typosquat-domain checks cover gaps in the filter. For large packages, giving the agent a codemap plus an on-demand ReadFile tool beat both forwarding the flagged chunk and rechunking, reaching 95.2% end-to-end accuracy with no runtime errors. Projected costs are about $0.025 per median package and $0.072 at p90, and a crawler polls npm and PyPI every 10 minutes, caching verdicts by hash and diffing against the previous version.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Supply chain security](https://swe.quest/tags/supply-chain-security.md) (Security)
- [Threat detection](https://swe.quest/tags/threat-detection.md) (Security)
- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)

## Prerequisites

- LLM prompting and tool calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- package registries like npm and PyPI
- software supply chain attacks ([easy posts on Supply chain security](https://swe.quest/tags/supply-chain-security.md?difficulty=easy))

## Keywords

BewAIre, Datadog, npm, PyPI, osv.dev, Hackerbot, LLM-as-judge

## Related posts

- [Detecting malicious pull requests at scale with LLMs](https://swe.quest/articles/detecting-malicious-pull-requests-at-scale-with-llms-18b7d45442154d44.md): Datadog Engineering · 2025-10-21 · Medium · 12 min read · Supply chain security, Threat detection, LLMs, Code review, Evaluation
  Datadog's SDLC Security team built BewAIre, an LLM-based reviewer that classifies the diff of every merged PR (nearly 10,000 a week) as benign or malicious, with a written rationale emitted as a security signal for real-time triage.
- [Coding Agent Horror Stories: The 29 Million Secret Problem](https://swe.quest/articles/coding-agent-horror-stories-the-29-million-secret-problem-7f5056c95d2769e4.md): Docker · 2026-07-28 · Medium · 12 min read · Supply chain security, AI for coding, Sandboxing & isolation, JavaScript, AI agents
  The s1ngularity supply-chain attack on the Nx npm package used a post-install script to find installed AI coding CLIs (Claude Code, Gemini CLI, Amazon Q) and invoke them with permission-bypass flags like --dangerously-skip-permissions, prompting the agent to inventory secrets across the home directory before exfiltrating them to public repos under the victim's GitHub account.
- [Building an agentic harness that outlasts the model](https://swe.quest/articles/building-an-agentic-harness-that-outlasts-the-model-75504578038e6cc5.md): Shopify Engineering · 2026-07-29 · Medium · 8 min read · AI agents, Application security, Vulnerability research, LLMs, Ruby
  Shopify's AppSec team built Dispatch, a Ruby-orchestrated multi-agent harness that partitions codebases, runs parallel category-specific Hunter agents, verifies candidates with tests written by a different model inside each app's existing test suite, and opens draft fix PRs.
- [When an AI agent came knocking: Catching malicious contributions in Datadog’s open source repos](https://swe.quest/articles/when-an-ai-agent-came-knocking-catching-malicious-contributions-in-datadog-s-efd5d1e84be0c443.md): Datadog Engineering · 2026-03-09 · Medium · 16 min read · Supply chain security, CI/CD, Threat detection, AI agents, Open source
  An AI agent called hackerbot-claw targeted Datadog's public repositories in late February 2026.
- [Fixing security vulnerabilities with AI](https://swe.quest/articles/fixing-security-vulnerabilities-with-ai-6cf393c64f079c26.md): GitHub Engineering · 2024-02-14 · Medium · 10 min read · AI for coding, Static analysis, Application security, LLMs, Evaluation
  Copilot Autofix turns CodeQL security alerts into LLM-suggested fixes by building a prompt from the query help, the alert message, and code snippets along the data-flow path.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
