Skip to main content

Pre-Installation AI Agent Tool Risk Analyzer

Project description

AgentLens

License

AgentLens is a deterministic, pre-installation security wrapper for AI Agent skills, tools, and repositories.

It forces targeted code to run through a custom static analysis risk scoring model before allowing it to interact with your execution environment, aggressively identifying common vulnerabilities introduced by AI-generated external dependencies.

Key Features

  • Deterministic Scanning: Fully bounded risk scoring engine that prevents unbounded linear score accumulation.
  • Categorical Risk Silos: Independent evaluation of code_execution, prompt_injection, filesystem_access, and network_access.
  • Policy-Driven Decision Engine: Automatically maps combined signals into actionable ALLOW, WARN, or BLOCK decisions based on YAML configuration.
  • Context-Aware Scoring: Intelligently extracts structural signals (like is_framework) to separate high-risk raw execution from safe library runtime internals.
  • Confidence Scoring: Validates the strength and ambiguity of risk signals, gracefully downgrading uncertain blocks to warnings.
  • LLM Semantic Analysis: Optional second-opinion pass powered by Azure AI Foundry that evaluates the true intent of flagged code snippets, reducing false positives without sacrificing security coverage.
  • Registry Targets: Scan packages directly with npm:<package> or pypi:<package> (downloads are extracted with path-traversal checks on archives).
  • JS/TS Guardrails: JavaScript and TypeScript files are scanned for high-risk execution patterns, and npm: packages with JS/TS sources are never treated as clean solely because the Python AST analyzer found nothing.
  • Output Formats: Rich CLI formatting (yielding clear human-readable explanations and recommendations), or full Pydantic-validated JSON for programmatic aggregation.

Installation

Install from PyPI:

pip install agentlens-scanner

Install with the optional prompt-injection prefilter:

pip install "agentlens-scanner[injection]"

Install from source:

git clone https://github.com/ellacarmon/AgentLens.git
cd AgentLens
pip install .

Usage

Scan targets

  • GitHub: HTTPS URL to a repository (must be github.com).
  • Local path: Directory or file on disk.
  • npm: npm:<package> (e.g. npm:lodash) — fetches the latest tarball from the public registry.
  • PyPI: pypi:<package> (e.g. pypi:requests) — prefers an .tar.gz sdist, otherwise a .whl.

Examples:

agentlens scan https://github.com/langchain-ai/langchain
agentlens scan ./local_skill_folder
agentlens scan npm:some-package
agentlens scan pypi:some-project

Check the installed CLI version:

agentlens --version

To integrate into programmatic pipelines (such as a GitHub action or a pre-flight execution check), use --json:

agentlens scan https://github.com/microsoft/autogen --json

For pipeline safety, AgentLens automatically returns semantic exit codes reflecting the decision engine state:

  • 0: ALLOW
  • 1: WARN
  • 2: BLOCK

To enforce custom strict policies, provide a custom YAML policy template:

agentlens scan ./local_skill_folder --policy custom_policy.yml

LLM Semantic Analysis (Azure AI Foundry)

The static analysis engine is fast and deterministic, but can produce false positives — for example, flagging a legitimate subprocess call used for a local math calculation the same way it flags a reverse shell. The semantic analysis layer adds a second-opinion pass that uses an LLM to evaluate the true intent of the flagged code snippet.

When enabled, the hybrid engine runs the static tier first. If the result is WARN or BLOCK and there is at least one code_execution or network_access finding, the LLM is invoked once per scan on a small batch of the strongest such findings (up to three), so the model sees a bit of cross-file context instead of a single line in isolation. A high-confidence ALLOW verdict from the LLM overrides the static decision, updating both the final verdict and the recommendation.

To print which findings were sent to the model (paths, rules, severities), run the CLI with verbose on the top-level command: agentlens -v scan ... --semantic.

Setup

Set the following environment variables:

export AZURE_OPENAI_API_KEY=your-key
export AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
export AZURE_OPENAI_API_VERSION=2024-12-01-preview  # optional, this is the default

Usage

Add --semantic to any scan to enable the hybrid engine:

agentlens scan https://github.com/langchain-ai/langchain --semantic

Override the default deployment name or confidence threshold:

agentlens scan https://github.com/langchain-ai/langchain --semantic --semantic-model gpt-4o --semantic-threshold 0.90

When a semantic override is applied, the output includes a dedicated section:

Semantic Analysis:
  Decision: ALLOW
  Confidence: 0.95
  Explanation: The subprocess call is used for a bounded local computation with no external I/O.
  Flagged Pattern: subprocess.run with shell=True

If the LLM API is unavailable or returns an unparseable response, AgentLens degrades gracefully to the static verdict — the scan never fails due to an LLM outage.

Releasing To PyPI

Build the source distribution and wheel:

python -m pip install --upgrade build twine
python -m build
twine check dist/*

Upload manually with Twine:

python -m twine upload dist/*

For a safer long-term setup, prefer PyPI Trusted Publishing from GitHub Actions instead of storing a long-lived PyPI token in GitHub secrets.

Contributing

Please see CONTRIBUTING.md for details on submitting pull requests to the project.

Research

The archetype-based detection in AgentLens (Data Thief and Agent Hijacker) is grounded in:

Malicious Agent Skills in the Wild: A Large-Scale Security Empirical Study
Liu et al., 2026 · arXiv:2602.06547

This paper provides the first large-scale empirical study of malicious AI agent skills, confirming 157 malicious skills across 98,380 samples. Key findings that informed our detection model:

  • 84.2% of vulnerabilities reside in natural-language skill documentation (SKILL.md), not executable code.
  • The ecosystem splits into two negatively-correlated archetypes: Data Thieves (credential harvest + remote script execution, empirical OR=556 — a statistical Odds Ratio indicating these behaviors are 556x more likely to occur together) and Agent Hijackers (instruction override + autonomy suppression).
  • Advanced attacks use shadow features — capabilities present at runtime but absent from public documentation — in 100% of Level 3 (sophisticated) cases.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentlens_scanner-0.1.0.tar.gz (69.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentlens_scanner-0.1.0-py3-none-any.whl (66.7 kB view details)

Uploaded Python 3

File details

Details for the file agentlens_scanner-0.1.0.tar.gz.

File metadata

  • Download URL: agentlens_scanner-0.1.0.tar.gz
  • Upload date:
  • Size: 69.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for agentlens_scanner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8f98f5a745b28bb957b50c717cdb76e777975629848f77a898044d84fc37e34b
MD5 1f243648f607f9ff68409ad33f59dc8f
BLAKE2b-256 daf92bcd330cff1da1c1f87475ac619ddd70166ad85ede2380f4decb4fb99255

See more details on using hashes here.

File details

Details for the file agentlens_scanner-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentlens_scanner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c87041088ae3ee7adfcc9df6e65e53fce55579497a72f02cbd0630f745e622a5
MD5 e23f51e730e591a5e3030237240576f8
BLAKE2b-256 4e4db21bdf42760973d583996442261d4494596758190e2cb117c6f4768391e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page