Skip to main content

rein

PyPI CI License

Deterministic guardrails for AI-written code. rein catches what coding agents get wrong - leaked secrets, unsafe calls, imports that do not resolve, junk files, and commit-hygiene problems - turns them into a PASS / WARN / BLOCK verdict with fix guidance, and gates the code before it runs. It makes no LLM calls and no network requests: a reproducible check you can run in CI, a git hook, your editor, or an agent's own loop. Website: https://rein.software

Detection lives in pure functions under rein.core; the value is the engine around them - policy, verdict, steering, and remediation. The core stays dependency-free and can also govern best-of-breed external detectors (bandit, gitleaks, ruff, semgrep) as optional adapters. Thin adapters expose it: a CLI, an MCP server, a git pre-commit hook, a GitHub Action, and a VS Code extension.

Example

$ rein review app.py
[CRITICAL] secret.aws-access-key            app.py:3
           Possible AWS access key ID committed in source.
[HIGH    ] security.eval-exec               app.py:6
           Use of eval/exec runs arbitrary code; avoid it or strictly validate input.

Verdict: BLOCK

The verdict is BLOCK, so rein exits non-zero and the CI step, hook, or agent loop stops until the code is fixed.

Install

# End users: install the published package (the command stays `rein`)
pipx install rein-engine
# or: pip install rein-engine

# Developers: install from a clone with the dev extras
pip install -e ".[dev]"

Usage

# Scan files or directories for leaked credentials
rein scan .
rein scan src/config.py

# Scan only added lines from a diff (reads stdin)
git diff | rein scan --diff

# Run lint rules over Python code
rein lint .
rein lint src/ --ruff

# Flag unsafe-code patterns
rein security .

# Run all guardrails and get a PASS/WARN/BLOCK verdict
rein review .
# Run all guardrails plus external detectors (installed separately)
# Detectors can also be enabled declaratively via .rein.toml
rein review --bandit --gitleaks --semgrep .
# Show how to fix each finding
rein review --explain .
# Review only changed lines (reads working tree and stdin diff)
git diff | rein review --diff

# Machine-readable findings for CI or agents
rein scan --format json .
rein lint --format json src/

# Check a commit message and the staged files
rein commit-check -m "feat(auth): add token refresh"
rein commit-check                 # uses the last commit message and staged files
# Note: commit-check and pre-commit hooks will strictly flag any modifications to rein's own config files as HIGH.
# They also provide advisory warnings (MEDIUM/LOW) if you attempt to commit junk/slop files (e.g. .DS_Store, temp.py).

rein exits non-zero on any finding at HIGH severity or above, so it works as a CI step or a pre-commit hook.

GitHub Action

You can drop rein directly into your GitHub Actions pipeline. It reviews a path and uploads the findings as SARIF, so they surface in the Security tab:

name: CI
on: [push, pull_request]

jobs:
  rein:
    runs-on: ubuntu-latest
    permissions:
      contents: read          # checkout the repository
      security-events: write  # upload SARIF to the Security tab
      actions: read           # upload-sarif reads run metadata (private repos)
    steps:
      - uses: actions/checkout@v4
      - name: Run rein review
        uses: SametAtas/rein@v0.4.0
        with:
          path: src/
          output: rein.sarif

Code scanning (the Security tab) needs GitHub Advanced Security on private repositories. Where it is unavailable, set upload: false to produce the SARIF file as a build artifact instead of uploading it.

Coding agent integrations

rein plugs into agents you already use, as a deterministic gate on the code they write. Same code, same verdict, no extra model calls for the check.

aider

aider lints every file it edits. Point its lint command at rein:

aider --lint-cmd "rein review"

After each edit aider runs rein review <file>; on a BLOCK it feeds rein's findings back to the model to fix before continuing.

OpenHands

rein-openhands is a deterministic SecurityAnalyzer, a no-LLM alternative to the built-in LLMSecurityAnalyzer:

pip install rein-openhands
from rein_openhands import ReinSecurityAnalyzer

agent = Agent(llm=llm, tools=tools, security_analyzer=ReinSecurityAnalyzer())

VS Code

The rein VS Code extension shows rein's findings inline as you edit, and reviews the workspace, the staged git diff, or a commit message on demand. Also on Open VSX.

Configuration

Control the engine declaratively with a .rein.toml file at the root of your project to configure the rein review verdict policy, disable specific rules, and enable external detectors:

[policy]
fail_at = "high"          # severity at/above which a finding blocks
warn_at = "low"           # severity at/above which a finding warns

[policy.category_fail_at]
lint = "low"              # override fail threshold per category (secret/lint/security/commit/ruff)
secret = "critical"

[rules]
disabled = ["lint.todo-comment", "secret.jwt"]   # rule_ids to drop entirely

[[rules.custom]]
id = "no-print"
pattern = "\\bprint\\("
severity = "low"
message = "Avoid print() in production code"

[detectors]
# Declaratively enable external detectors (must be installed separately).
# Note: semgrep is a multi-language, rule-based detector and is heavier, so it is opt-in.
bandit = true
gitleaks = true
ruff = true
semgrep = true

You can override the path via rein review --config path/to.toml ..

Layout

src/rein/
  core/      pure checks: findings.py, pragmas.py, diffs.py, secrets.py, security.py, lint.py, commits.py, review.py, remediation.py, ruff.py, bandit.py, gitleaks.py
  report.py  shared output formatting and exit codes
  cli/       command-line adapter
  mcp/       MCP server adapter (stdio)
  hooks/     git pre-commit adapter
tests/       one test file per module

Steering an agent

Agents can use rein to check and correct their own code before committing. The reference implementation for this steering loop is rein.loop.run_loop (pure, bounded, agent injected).

  1. An LLM agent generates a patch.
  2. The loop runs review() or review_diff().
  3. If the verdict is BLOCK, the loop fetches suggest_fixes() and feeds the findings + guidance back to the agent as a prompt.
  4. The agent revises the code. The loop repeats until the verdict passes or the iteration bound is hit.

See examples/guarded_agent.py for a runnable demonstration.

Adopting on an existing repo

Record the current findings so CI only blocks on new issues:

rein baseline              # writes .rein-baseline.json
git add .rein-baseline.json
rein review --baseline .rein-baseline.json .

Findings already in the baseline are suppressed; only new ones trigger a BLOCK.

Use from an agent

Install with MCP support:

pip install -e ".[mcp]"

Start the stdio server:

rein-mcp

Client config snippet (e.g. for Claude Desktop or any MCP client):

{
  "mcpServers": {
    "rein": {
      "command": "rein-mcp",
      "transport": "stdio"
    }
  }
}

The server exposes eight tools: scan_secrets, check_commit, lint_code, scan_diff, check_security, review_code, suggest_fixes, and review_diff. The review tools (review_code and review_diff) accept an optional config object (same shape as .rein.toml) to steer with a custom policy.

A configurable Policy turns findings into a verdict and is how rein adapts to different standards and domains.

The rule the code follows: detection stays in core and returns Finding objects; adapters only gather input, call core, and render the result.

Test

pytest -q

License

Apache-2.0 (see LICENSE). Contributions require a Developer Certificate of Origin sign-off; see CONTRIBUTING.md.

Metadata

Release files for rein-engine 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rein-engine 0.4.0
File Size Uploaded Provenance Actions
rein_engine-0.4.0.tar.gz 112.6 kB With provenance Details for rein_engine-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rein-engine 0.4.0
File Interpreter ABI Platform Actions
rein_engine-0.4.0-py3-none-any.whl Python 3 none any Details for rein_engine-0.4.0-py3-none-any.whl

Total release size: 195.5 kB

Release files / rein_engine-0.4.0.tar.gz

Download URL rein_engine-0.4.0.tar.gz
Size 112.6 kB
Tags Source
SHA-256 checksum
How to use checksums
014981bfa064276ae2e354ab75dc39b09c0a72c2a5d4fc6d2eaa695e7a214365
BLAKE2b-256 checksum
How to use checksums
55dd10bf58e976df2484123bc31eea63132162d66c39abfda4ba995ca0c91196
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2026.

Transparency log

Release files / rein_engine-0.4.0-py3-none-any.whl

Download URL rein_engine-0.4.0-py3-none-any.whl
Size 82.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccd00bcf08fbbe889a68dc04a337e1ae76b6bb62a4be1fbef650a0c0e339ba16
BLAKE2b-256 checksum
How to use checksums
2d705efe5b28d78a0ec1c241cc557a7b0bc19714a67ba05be71d49cfca87b5bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2026.

Transparency log

Security for rein-engine 0.4.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rein_engine-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page