laya-guard
A local, safe-by-default AI risk guard for high-risk commands — deterministic pattern rules first, then the Laya decision model for the gray zone. It's defense-in-depth for the dockndevai MCP server suite: when a server runs in a permissive ("full permission") mode and is about to do something dangerous, it asks laya-guard "how risky is this?" and gets back allow / confirm / block with a reason — in milliseconds, on-device, nothing leaving the machine.
The one rule it obeys
The guard only ever tightens. It runs after a server's own deterministic gates have already permitted an action, and it can only add a confirmation or a block — it can never grant a permission those gates denied. When the model is unsure, unavailable, or the input looks adversarial, it fails closed (confirm/block, not allow). So turning it on is strictly safer than leaving it off — never weaker.
How it decides
- Deterministic patterns (always first). A block pattern (
rm -rf /,mkfs,curl … | sh,DROP TABLE,kubectl delete ns,shutdown, …) blocks outright; a confirm pattern (sudo,git push --force,docker rm, …) raises the floor to at least confirm. These make the guard useful even with no model loaded. - The laya model (gray zone). For everything else it asks four typed questions — is this destructive, exfiltration, privilege-escalating, and how large is the blast radius — and maps the answers (with calibrated confidence) to a risk level and a decision.
Run it
pipx install laya-guard
# fetch the laya model once (downloads are off by default):
LAYA_GUARD_ALLOW_DOWNLOAD=true python -c "import laya; laya.Router(preload=True)"
laya-guard # starts the daemon on http://127.0.0.1:8799
One-shot assessment (no server), handy for testing:
laya-guard evaluate "rm -rf /" # -> {"decision":"block","risk":"critical",...}
laya-guard evaluate "ls -la" # -> {"decision":"allow",...}
API
GET /health -> {"status":"ok","model_available":bool,"policy":{...}}
POST /evaluate {"tool":"run_command","command":"...","context":"..."}
-> {"decision":"allow|confirm|block","risk":"...","confidence":0.0,
"reasons":[...],"deterministic":bool,"model_available":bool}
Using it from an MCP server
The daemon returns an assessment; the calling server decides what to do per its mode. In the suite, mcp-mac-control (0.3.0+) ships a client that calls the guard from its high-risk tools:
MACCTL_GUARD_MODE=off(default) — disabled, no behaviour change.MACCTL_GUARD_MODE=monitor— assess and log what it would do; never blocks.MACCTL_GUARD_MODE=enforce— act: block, or require a human confirmation.
Start in monitor to see what it would catch, then flip to enforce.
Organization control
Point LAYA_GUARD_POLICY at a JSON file (see policy.example.json) to set your own block/confirm/allow patterns and thresholds, and ship it org-wide. Omitted keys fall back to the built-in defaults.
Safe by default
- Local & offline — the model runs on-device; the only network touch is the one-time laya checkpoint download, gated by
LAYA_GUARD_ALLOW_DOWNLOAD. - Loopback only — binds
127.0.0.1unlessLAYA_GUARD_ALLOW_REMOTE=true. - Fail-closed — unavailable/low-confidence/unknown ⇒ confirm or block, never a silent allow.
- Only tightens — never grants a permission the caller's deterministic gates denied.
See SECURITY.md.
Developing
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
ruff check src tests && mypy src && pytest # the policy tests need no model
Credits
Built on laya by Convai Innovations (Apache-2.0), a dependency, not vendored. See NOTICE.
Licence
MIT
Metadata
Release files for laya-guard 0.1.0
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 |
|---|---|---|---|---|
| laya_guard-0.1.0.tar.gz | 15.2 kB | Without provenance | Details for laya_guard-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| laya_guard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for laya_guard-0.1.0-py3-none-any.whl |
Total release size: 29.1 kB
Release files / laya_guard-0.1.0.tar.gz
| Download URL | laya_guard-0.1.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
319a7e29b1c97892d8770953d55dc5529b2333d9840d9f8a5b923ea13a27343f
|
|
BLAKE2b-256 checksum How to use checksums |
597793e6855023289637b142ded9b93594d707e29bf8291485268873873bde17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / laya_guard-0.1.0-py3-none-any.whl
| Download URL | laya_guard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d508dc79b5d77b40809b69c781fb30d46794471d628ee95220821721e14aa02a
|
|
BLAKE2b-256 checksum How to use checksums |
321f7e3b36e01c206c4298b067cf677d983c89b7e2dbb78cb8c9ce5f92a0acbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for laya-guard 0.1.0
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.