KernelGuard
KernelGuard is a rule-based kernel hack detector for GPU-kernel competition submissions.
The core module is kernelguard.py, which can:
- classify a single submission from stdin
- scan JSONL pair datasets
- scan submission parquet exports
- generate a rule audit from a local review corpus
- load runtime config from built-in profiles, TOML files, and command-line overrides
Current Layout
kernelguard.pyMain detector and audit tool.
Install
pip install kernelguard
With extras:
pip install "kernelguard[parquet]"
pip install "kernelguard[mcp]"
uv
One-shot (no install):
uvx kernelguard --help
uvx kernelguard --api-mode < submission.py
uvx --from "kernelguard[parquet]" kernelguard --parquet submissions.parquet
uvx --from "kernelguard[mcp]" kernelguard-mcp --version
Permanent install:
uv tool install kernelguard # core only
uv tool install "kernelguard[parquet]" # + parquet scanning
uv tool install "kernelguard[mcp]" # + MCP server
uv tool install "kernelguard[parquet,mcp]" # + parquet + MCP
uv tool install "kernelguard[api]" # + HTTP API server
Entry points after installation: kernelguard, kguard, kernelguard-mcp, kguard-mcp, kernelguard-api, kguard-api.
Quick Start
Single kernel from stdin:
kernelguard --api-mode < submission.py
JSONL scan:
kernelguard --jsonl /path/to/pairs.jsonl --output-dir out/
Parquet scan:
kernelguard --parquet /path/to/submissions.parquet --output-dir out/
MCP Server
KernelGuard runs as a local MCP server over stdio.
kernelguard-mcp # default profile
kernelguard-mcp --profile strict # higher-recall review mode
kernelguard-mcp --version
Two tools:
analyze_code— analyze a code string, return detection results.analyze_file— read a file path, return detection results plus resolved path.
Both accept optional metadata (for score-based detection) and profile parameters.
The server is read-only: no resources, prompts, scan tools, or write operations.
HTTP API Server
KernelGuard runs as an HTTP API server for integration with services like KernelBot.
kernelguard-api # default: 127.0.0.1:8088
kernelguard-api --host 0.0.0.0 --port 80 # public
kernelguard-api --profile strict # higher-recall mode
Endpoints:
GET /health— returns{"status": "ok", "version": "...", "profile": "..."}.POST /analyze— accepts{"code": "...", "metadata": null, "profile": "default"}, returns detection results.
The API server keeps KernelGuard loaded in memory, eliminating cold-start latency from subprocess invocations.
Runtime Config
The standalone repo already includes the later config-support additions from the newer line of development.
Runtime behavior can be controlled with:
--profileSelect a built-in profile.--configLoad a TOML config file.--setApply dottedkey=valueoverrides from the CLI.--export-configPrint or write the resolved config and exit.
Examples:
Export the default resolved config:
kernelguard --export-config
Export the strict profile:
kernelguard --profile strict --export-config
Run with a TOML config file:
kernelguard --config kernelguard.toml --jsonl /path/to/pairs.jsonl --output-dir out/
Apply a one-off override:
kernelguard --set 'entrypoints.names=["kernel"]' --api-mode < submission.py
The config layer covers:
- rule policy overrides
- score thresholds
- duplicate handling
- classification behavior
- entrypoint-name configuration
Compatibility
The primary public interfaces are:
--api-modefor a single kernel--jsonlfor pair datasets--parquetfor submission exports
The detector also keeps some legacy compatibility for older internal audit/archive workflows so historical corpora can still be reused.
Audit Behavior
--audit-rules is meant to run in a workspace that contains the audit corpora and prior detector outputs.
This is an internal evaluation mode, not a normal first-run path.
If no audit fixtures are discovered, the command exits with a clear error instead of silently producing an empty audit report.
Minimal audit run:
kernelguard --audit-rules --output-dir audit_out/
If you want to drive audit mode from explicit inputs, put them in your config file:
[audit]
archive_dir = "/path/to/archive"
ground_truth_dir = "/path/to/ground_truth_dir"
manual_review_files = [
"/path/to/manual_review_1.json",
"/path/to/manual_review_2.json",
]
filtered_results_path = "/path/to/filtered_results.jsonl"
To compare old and new detector outputs explicitly during audit, put them in config too:
[audit.result_files]
old = "/path/to/old_results.jsonl"
new = "/path/to/new_results.jsonl"
Then run:
kernelguard --config kernelguard.toml --audit-rules --output-dir audit_out/
Generated audit artifacts include:
classifier_fixture_manifest.jsonrule_audit_report.jsonrule_audit_report.md
Generated scan artifacts include:
detection_results_*.jsonldetection_summary_*.jsoncleaned_pairs.jsonl
These generated files are ignored by the repo-level .gitignore.
Metadata
Release files for kernelguard 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kernelguard-0.3.2.tar.gz | 96.9 kB | Without provenance | Details for kernelguard-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kernelguard-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for kernelguard-0.3.2-py3-none-any.whl |
Total release size: 193.8 kB
Release files / kernelguard-0.3.2.tar.gz
| Download URL | kernelguard-0.3.2.tar.gz |
|---|---|
| Size | 96.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f8c5c64a352a9cbb52c767135b27fdcee2fc7b1c5a40017428e824b2f584aba
|
|
BLAKE2b-256 checksum How to use checksums |
e25132b7fbdc4aa82ea4227ac39ccd7d5477c457c9c60f1464708a0f92e0017b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / kernelguard-0.3.2-py3-none-any.whl
| Download URL | kernelguard-0.3.2-py3-none-any.whl |
|---|---|
| Size | 96.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb90db9a35b34224ae3aad65c894b587bdc114a19e9b623503a87dec2996591e
|
|
BLAKE2b-256 checksum How to use checksums |
5c35730d38ff2d664b50ae941941ac2e73186e5a0de9263f26a608aa453f0819
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for kernelguard 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.