afk-guard
Free, local-only guard rails for people who run AI agents. Apache-2.0. Python 3.9+. No network calls. Codex TOML on Python 3.9 and 3.10 uses the tomli package; Python 3.11 and newer use the standard-library parser.
Status: 0.1.1 (Apache-2.0). Repository: https://github.com/alvelda/afk-guard
Context lines mask the full span of a matched secret. The canary registry is written only in a directory you name.
It does five things:
scan— find leaked secrets in files/directories (regex rules plus entropy). Values are redacted in all output: a fixed[REDACTED]label, the rule name, a coarse length bucket (not the exact length), and a short location fingerprint. The fingerprint is a hash of the rule, the normalized path, and the line number. It is not a hash of the secret. No characters from the secret are shown, including a short prefix. The same secret in two places does not share an id. Two findings with the same rule, path, and line do share an id (collision accepted; no cross-file value dedupe).--show-contextmasks the union of overlapping matched spans on the line, so a longer overlap cannot leave a secret suffix.canary— plant fake, tempting credentials and watch whether anything touches them. Local log, optional webhook to your own listener. No signups, no vendor contact. The registry check applies only to the directory you name.mcp-check— check OpenClaw / MCP client configs (Cursor, Codex, OpenClaw, genericmcpServersJSON/TOML) against a bundled advisory list taken from the AFK Cyber Desk feed.--pin-staterecords a pin and a content hash and reports drift when that covered set changes. See "MCP pin file".inject-check— screen a text file or stdin for instruction patterns (ignore-previous, marker file writes, tool-call requests, and similar). Offline and deterministic. A low result is not proof the text is safe, and the check does not block anything.dashboard— a local HTML report: one file (inline CSS and SVG, no network) from scan, canary, mcp-check, or inject-check JSON. Pure--exampleis badged EXAMPLE DATA. Live input is not. Findings show[REDACTED], a length bucket, and a location fingerprint of rule, path, and line. No secret prefix is displayed.
Install / run
python3 -m afk_guard --help # from this directory
pip install . # optional; gives the `afk-guard` command
python3 -m unittest discover -s tests
Examples
afk-guard scan ~/projects --counts-only # counts only, no per-finding lines
afk-guard scan ~/projects --format json # redacted findings
afk-guard scan --procs # also scan /proc/*/cmdline (Linux; never environ)
afk-guard canary plant ./sandbox --kinds aws,github,env
afk-guard canary listen --port 8099 # loopback-only listener, writes JSONL
afk-guard canary check ./sandbox --log agent.log --listener-log afk-canary-hits.jsonl
afk-guard mcp-check # discovers common config locations under $HOME
afk-guard mcp-check ./repo --hygiene # plaintext secrets, unpinned npx, http remotes
afk-guard mcp-check ./repo --no-discover --pin-state .afk/mcp-pins.json
afk-guard mcp-check ./repo --no-discover --pin-state .afk/mcp-pins.json --update-pins
afk-guard inventory-preview ./inventory.json # PREVIEW: offline inventory JSON, no accounts contacted
afk-guard inject-check ./untrusted/page.txt # versioned JSON; exit 1 when severity is high
afk-guard inject-check - # read stdin, size-capped
afk-guard dashboard --example -o afk-guard-dashboard.html # offline HTML, EXAMPLE DATA
afk-guard dashboard --scan scan.json --inject inject.json -o report.html
Exit codes: scan returns 1 when a real finding is present. mcp-check returns 1 when an advisory hit, an extension hit, a pin/content drift finding, or a pin safety finding is present (--exit-zero forces 0). A config that could not be parsed is a high-severity config-unparseable safety finding, including when no pin file is requested, so that run exits 1 rather than 0. There is no separate warning exit code. inject-check returns 1 when severity is high (medium and low return 0). dashboard returns 1 when a live report has a failing check, and 2 when the JSON is rejected, --example is mixed with a live input, or the HTML cannot be written. Pure --example returns 0. JSON for mcp-check uses schema afk-guard/mcp-check/v1 with schema, tool, version, generated_at, and findings. Severity info means a pin baseline was recorded or refreshed and does not fail the process. The pin file schema is afk-guard/mcp-pins/v1. Hygiene findings carry severity for CI but do not by themselves change the process exit.
dashboard --input accepts afk-guard/dashboard-html/v1, afk-guard/scan/v1 (or scan JSON with findings plus files_scanned, total_real, or counts), afk-guard/inject-check/v1 (or tool: inject-check), afk-guard/mcp-check/v1, schema-less mcp-check JSON that has hits, extension_hits, or advisory_db, and afk-guard/canary/v1 (or alerts / planted). Other shapes exit 2 and write no file. afk-guard/mcp-check/v1 is displayed when a document has it. Pin and drift rows show only if that document includes them. Core len= buckets and this page's integer-length buckets are not the same scale.
-o writes a new file in the destination directory and replaces that directory entry. A symlink at the output path is not followed, so the symlink target is not truncated. An existing regular file is replaced.
What it will NOT do (read this)
- A clean result does not mean you are safe. It means these rules found nothing in the files it looked at.
inject-checkis the same kind of limit: it only matches a fixed list of instruction patterns. inject-checkreads at most 1 MB. It does not print the source text. It does not call the network.- It cannot see secrets in places it does not read (password managers, browser stores, memory, environment of other processes, remote systems).
~/.ssh,~/.secretsand browser profiles are only scanned if you point it there. - Entropy findings are guesses. Expect false positives (hashes, test data, minified code). Add
afk-guard:ignoreon a line to skip it. Placeholders and plain hex hashes are skipped. - It does not delete files or rewrite MCP configs, source trees, or secret stores. Rotate real secrets yourself.
canary plantwrites decoy files and a registry only in the directory you name.mcp-check --pin-statewrites the pin file (mode0600); it rewrites that file only with--update-pins. - Files over 1 MB, binary files, and common dependency/build dirs are skipped.
- Canary "accessed" uses file access time (atime). Many systems mount with
noatime; treat it as low confidence. Stronger signals: value seen in a log you give it, or a callback hit. - The canary registry is written only in a directory you own that is mode exactly
0700and not a symlink. Group or other permission, or the sticky bit on that directory, is refused. The tool does not chmod it. A sticky ancestor such as/tmpabove that private directory is not inspected and is not a reason to refuse. The registry file is mode0600. A symlink or a registry that is not mode0600is refused, not repaired. Unix directory descriptors are required; other platforms refuse. This assumes your local user account is not already compromised. It does not claim protection against root, or against someone replacing a parent mount such as/tmp. - Canaries are fake and carry the marker
AFKGUARD. The payment canary uses ansk_test_prefix on purpose so it does not look like a live key to other scanners. Planting them in a repo you scan with other tools will trigger those tools: plant in a sandbox directory.
Advisory data (mcp-check)
afk_guard/data/advisories.json is taken from the AFK Cyber Desk feed (agentfieldkit.com/agents/cyber/feed.json, 47 items at build time; 24 had a matchable package and are bundled). For each entry we keep the feed id, title, date, CVE id and source URL, and mark confidence:
- Titles, dates, CVE ids and source URLs are copied from the feed by id.
- Package names and fixed versions were transcribed by hand from the feed titles and are not independently verified. Two package ids are guesses and flagged
name_unverified:@samanhappy/mcphubandawslabs.aws-serverless-mcp-server. - Three OpenClaw entries have no version data and are low confidence.
Verdicts:
affected,possibly-affected,check-version,present,not-affected. Where no fixed version is known the verdict ischeck-version, never "safe". Always follow the source URL before acting.
MCP pin file
--pin-state stores afk-guard/mcp-pins/v1: one record per config group + server name. The same server name in two groups is two pins plus a duplicate-server-name finding (not last-wins). A missing pin file records a baseline only when every config parsed and every launch is covered. That baseline is severity info. Drift, a bad pin file, or a refused launch exits 1 and does not rewrite the pin file. --update-pins replaces the pin file with the current covered set.
pin is a recognized version (1.2.3, v1.2.3, a short prerelease such as 1.2.3-beta.1, or the tags latest / next) or empty when the launcher has no version. A version tail that does not match that syntax is not stored and is not echoed. Empty is "no version pin", not a claim that an unrecognized tail was verified.
content_hash is sha256: plus the SHA-256 of canonical JSON (sorted keys, no extra whitespace) of this projection:
- server name and command
- boolean flags, path arguments, and the syntax-valid package spec
- env key names, sorted (env values are not hashed and not stored)
- package ecosystem, name, and syntax-valid version
- URL scheme, host, port, and path
integrity: full means that projection only. It includes path arguments. It is not a secret-free claim over path strings: a credential placed in a path is still hashed. It does not cover env values. Credential-shaped arguments (--token and similar), token-shaped arg values, URL userinfo, URL query or fragment, unrecognized version tails, and unclassified args are integrity: unsupported. They are not hashed. No verified baseline is written. Changing only the secret must not look like a clean, fully covered pin. A group-or-other-readable pin file is repaired to mode 0600 on read when that repair can be done on the open file; a pin file that cannot be read is left unchanged.
Tests
python3 -m unittest discover -s tests in this repository runs 112 tests. Test secrets are assembled at runtime, so the repo contains no complete token literal. Instruction-pattern fixtures under test-fixtures/injection/ are fake drill text. Dashboard fixtures are fake too: no live tokens, and the HTML does not load a network.
Paid features are available separately.
License
Apache-2.0, see LICENSE. Commercial terms for paid features will be published separately.
Metadata
Release files for afk-guard 0.1.1
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 |
|---|---|---|---|---|
| afk_guard-0.1.1.tar.gz | 68.4 kB | Without provenance | Details for afk_guard-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| afk_guard-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for afk_guard-0.1.1-py3-none-any.whl |
Total release size: 140.1 kB
Release files / afk_guard-0.1.1.tar.gz
| Download URL | afk_guard-0.1.1.tar.gz |
|---|---|
| Size | 68.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4106e4ea482b27fa34fbb520a23b529d7d1db0fa45ba73f4a54803639386e601
|
|
BLAKE2b-256 checksum How to use checksums |
4370d403321ac9c1ca655940eeb9cb683f0241dc7ffe24db2ced753ef6b8ceb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / afk_guard-0.1.1-py3-none-any.whl
| Download URL | afk_guard-0.1.1-py3-none-any.whl |
|---|---|
| Size | 71.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d6750a7b06e4d8b166d6f73206fb897861e40fcf63cff663546c501b4e652b4
|
|
BLAKE2b-256 checksum How to use checksums |
a18057a49a1448d3431bc8e5128c856e4d9f36045abc13f43c4b2da11aa1ef54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for afk-guard 0.1.1
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.