Metadata-Version: 2.4
Name: envcert
Version: 0.4.2
Summary: Independent, extensible integrity verification and evidence generation for AI training and evaluation environments
Project-URL: Homepage, https://github.com/EricMaxwellnetizen/envcert
Project-URL: Repository, https://github.com/EricMaxwellnetizen/envcert
Project-URL: Issues, https://github.com/EricMaxwellnetizen/envcert/issues
Author: EnvCert contributors
License: Apache-2.0
License-File: LICENSE
Keywords: ai,attestation,benchmark,evaluation,harbor,reward-hacking,verification
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: jsonschema>=4.20; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: twine>=5.0; extra == 'dev'
Provides-Extra: validate
Requires-Dist: jsonschema>=4.20; extra == 'validate'
Description-Content-Type: text/markdown

# EnvCert

[![PyPI](https://img.shields.io/pypi/v/envcert.svg)](https://pypi.org/project/envcert/)
[![CI](https://github.com/EricMaxwellnetizen/envcert/actions/workflows/ci.yml/badge.svg)](https://github.com/EricMaxwellnetizen/envcert/actions/workflows/ci.yml)
[![Docs](https://img.shields.io/badge/docs-mkdocs-blue.svg)](https://ericmaxwellnetizen.github.io/envcert/)

**Integrity verification and evidence for AI training and evaluation environments.**

EnvCert checks whether the thing you measure models with is trustworthy:
a task bundle (instruction, Docker environment, reference solution,
verifier) or the dataset file itself (JSONL/JSON/CSV). Is the answer
leaked to the agent? Can agent-controlled files influence the verifier?
Would a *cheating* solution pass? Are train and test rows the same rows?
Is the build reproducible, the evidence verifiable?

It answers with explicit, deterministic findings (never a single score),
schema-versioned reports (text/JSON/SARIF/Markdown/HTML), a cheat-agent
battery that *proves* false passes by execution, deterministic fixes,
and an optional digest-bound [in-toto](https://in-toto.io) attestation.

EnvCert is **not** a certification authority and never claims an environment
is unhackable. It is an independent, extensible verification and evidence
layer — complementary to Harbor / NeMo Gym (which run tasks), BenchJack /
trustworthy-env (which hunt novel exploits with AI agents), and Trivy/
Hadolint/Semgrep (CVE/lint/SAST). No LLM, no API key, no account:
everything above runs offline. See `docs/research/PRODUCT_REVIEW.md`
for the evidence that this gap is real, and
`docs/research/COMPETITIVE_ANALYSIS.md` for the feature matrix.

## Who is it for?

Environment developers, benchmark maintainers, AI researchers and model
developers who publish or consume evaluation tasks and need to know *what
was checked, what failed, what could not be checked, and whether someone
else can reproduce that*.

## Install

Requires Python 3.11+.

```bash
pip install envcert          # from PyPI
pipx install envcert         # or isolated
# From a checkout of this repository:
pip install .
```

The core has **zero runtime dependencies**: static analysis works offline,
with no Docker, account, network or API key.

## Quick start

```bash
envcert check ./examples/safe-environment
envcert check ./examples/intentionally-vulnerable-environment   # exit 1: try it
envcert check ./my-task --format json --output report.json
envcert check ./my-task --format sarif --output envcert.sarif
envcert check ./my-task --format markdown --output summary.md    # PR-ready
envcert check ./my-task --format html --output report.html       # shareable
envcert check ./data/train.jsonl                                 # dataset files, no bundle needed
envcert check ./my-task --execution docker                       # gold + no-op + cheat battery
envcert fix ./my-task                                            # dry-run deterministic fixes
envcert fix ./my-task --apply
envcert new ./my-new-task                                        # scaffold that passes check
envcert verify report.json --task ./my-task
envcert list-checks
envcert explain EC066
```

Real output (safe example, abridged):

```text
EnvCert 0.4.0  report schema 1.0.0
Task: envcert/hello-file  adapter=harbor  files=8
Profile: harbor  execution: none  fail_on: CRITICAL, HIGH

[PASS] EC001 (INFO/PASS) Task structure is recognisable and complete
[PASS] EC011 (INFO/PASS) Reference solution is not copied into the agent environment
[PASS] EC020 (INFO/PASS) Verifier runs separated from the agent where the framework supports it
[PASS] EC051 (INFO/PASS) Verifier produces a reward in the framework's expected location
[SKIP] EC060 (INFO/NOT_RUN) Reference (gold) solution passes the verifier
       Dynamic checks are opt-in: re-run with --execution docker or --execution local-python.
Summary: 43 findings {'PASS': 25, 'NOT_APPLICABLE': 8, 'NOT_RUN': 10}
Policy: PASSED (fail_on=CRITICAL, HIGH)
```

The intentionally vulnerable example produces (among others):

```text
[FAIL] EC010 (HIGH/FAIL)  .git metadata is inside the Docker build context and not excluded by .dockerignore
[FAIL] EC011 (CRITICAL/FAIL) Reference/answer material inside the build context is plausibly copied into the image by 'COPY .'
[FAIL] EC052 (CRITICAL/FAIL) Possible unconditional-success path in verifier: unconditional 'echo 1 > reward.txt'
[WARN] EC021 (HIGH/WARN) 'environment/conftest.py' is in an agent-visible area and pytest auto-loads conftest.py ...
```

## What it checks

43 checks with stable public IDs (full catalog:
`docs/architecture/CHECK_CATALOG.md`, or `envcert list-checks -v`):

| Area | Checks | Examples |
|---|---|---|
| Structure | EC001–EC003 | missing verifier/instruction, absent reference solution |
| Leakage | EC010–EC014 | .git in build context, solution copied into image, gold files, hard-coded secrets, instruction disclosing the solution |
| Agent/verifier boundary | EC020–EC024 | shared verifier mode, sitecustomize/conftest shadowing, PATH tool shadowing, world-writable paths, docker.sock/privileged |
| Docker | EC030–EC033 | unpinned base images, root user, remote ADD / curl\|sh, undeclared network policy |
| Dependencies | EC040–EC041 | unpinned pip deps, unverified downloads |
| Verifier quality | EC050–EC056 | missing/empty verifier, no reward production, unconditional success, assertion-free tests, self-reported rewards (AST data-flow), eval/unsafe-deserialisation in the verifier |
| Dataset integrity | EC080–EC085 | answer embedded in the prompt, duplicate/near-duplicate rows, train/test overlap, degenerate labels, broken rows, inconsistent grading specs |
| Multi-step | EC004 | per-step instruction/verifier completeness (plus per-step EC002) |
| Dynamic (opt-in) | EC060–EC062 | gold run, no-op negative control (docker/local/external), repeatability |
| Cheat battery (opt-in) | EC066 | deterministic cheat agents — stub solution, conftest outcome-faking, forged reward file, verifier tampering — must all be rejected |
| Mutation (opt-in) | EC063–EC064 | AST mutants of a Python solution; literal mutants of shell solutions under Docker |
| External companions (opt-in) | EC070–EC072 | Hadolint, Trivy, Semgrep — run only when installed and `--external-tools` is passed |

Every finding carries evidence, a severity, a confidence, a remediation and
stated limitations. Heuristics report WARN — EnvCert does not present a
potential exposure as a confirmed vulnerability.

## What it cannot do

- Prove a verifier semantically correct, or an environment unhackable.
- See runtime mounts/configuration outside the task bundle (static mode).
- Scan base images for CVEs (use Trivy/Grype) or replace an adversarial
  audit (BenchJack-style) for high-stakes benchmarks.
- Dynamic Docker checks need a Docker daemon; `local-python` execution has
  **no sandbox** and must only be used on trusted tasks. See
  `docs/guides/DYNAMIC_EXECUTION.md`.

## Dynamic, cheat-battery & mutation checks (opt-in)

```bash
envcert check ./my-harbor-task --execution docker                 # restricted container run
envcert check ./examples/python-task --execution local-python --mutation
# EC060 PASS gold, EC061 PASS no-op rejected, EC062 PASS repeatable, EC063 mutation rejection rate
# EC066: deterministic cheat agents (stub solution, conftest outcome-faking,
#        forged reward file, verifier tampering) are played against your
#        verifier -- a cheat that passes is a proven false pass, not a heuristic.
```

## Datasets, fixes and scaffolding

```bash
envcert check ./train.jsonl            # answers-in-prompts, duplicates, split overlap, degenerate labels
envcert check ./data/                  # every .jsonl/.json/.csv beneath a directory (train/test aware)
envcert fix ./my-task                  # dry-run: deterministic, idempotent remediation plan
envcert fix ./my-task --apply          # write it (.dockerignore, declared policies), then re-check
envcert new ./my-task --name org/my-task   # a Harbor task scaffolded to pass `envcert check`
```

Pre-commit: `repo: https://github.com/EricMaxwellnetizen/envcert` with hook
id `envcert` (tasks) or `envcert-dataset` (data files). Third-party checks
can register under the `envcert.checks` entry-point group — no fork needed.

## Reports, verification, attestations

```bash
envcert check ./my-task --format json --output report.json
envcert verify report.json --task ./my-task        # schema + consistency + bundle digest
envcert verify report.json --task ./my-task --recheck   # + re-run the static checks and compare
envcert verify report.json --baseline old.json     # verify the baseline suppression
envcert schema                                     # published JSON Schema (report 1.0.0)
envcert attest report.json --output attestation.json          # in-toto Test Result statement
envcert attest report.json --dsse --sign --key cosign.key     # DSSE + Cosign, when installed
envcert verify-attestation attestation.json --key cosign.pub  # verify a detached .sig
```

`verify` recomputes policy and summary counts from the findings, so editing
`policy.passed` or the counters is detected; `--recheck` additionally proves
that the report's findings are the findings EnvCert produces for the task.
Reports that rely on baseline suppression must be verified with `--baseline`.
Unsigned attestations are labelled unsigned everywhere and require
`--allow-unsigned` for structural verification only — they are portable
evidence records, not cryptographic proof. Report fields and the attestation
extension are specified in `docs/architecture/REPORT_SCHEMA.md`.

## GitHub Actions

```yaml
- uses: EricMaxwellnetizen/envcert@v0.4.0   # or @v0 for the latest 0.x
  with:
    path: ./my-task
    fail-on: critical,high
    sarif: envcert.sarif   # optional, for GitHub code scanning
```

See `action.yml` (composite action), `examples/github-actions/` and
`docs/guides/CI.md`. Static checks by default; dynamic execution only when
you explicitly select it.

Exit codes: `0` policy passed · `1` policy failed · `2` invalid
input/config · `3` internal/execution error.

## Supported formats

| Format | Status |
|---|---|
| Harbor task directories (task.toml schema 1.x, incl. multi-step `steps/`) | Implemented and fixture-tested |
| Generic Docker task bundles (Dockerfile + tests/solution) | Implemented, reduced-confidence heuristics |
| NeMo Gym datasets (dataset.toml / verifier.py / JSONL rows) | Implemented (static + EC065 probing; Resources-Server HTTP probing not yet) — `examples/nemo-gym-dataset` |
| Inspect AI evaluations (@task Python files) | Implemented (static) — `examples/inspect-eval` |
| Dataset files (`.jsonl` / `.json` / `.csv`, SWE-bench/NeMo/OpenAI-style fields) | Implemented (EC080–EC084) — `envcert check data.jsonl` |

Dynamic execution modes: `docker` (restricted), `local-python` (trusted
pytest tasks, no sandbox), `external` (your disposable-VM/remote runner via
a documented JSON protocol). OCI image digests can be bound with
`--image`/`--image-digest`; Cosign OCI attestation is available via
`envcert attest --image name@sha256:...` and `envcert verify-attestation`.

## Configuration

`envcert init` writes `envcert.toml` (profiles: harbor/strict/minimal/ci,
per-check enable/disable, `fail_on` policy). See `docs/guides/CONFIGURATION.md`.

## Contributing

See `CONTRIBUTING.md` and `docs/guides/WRITING_A_CHECK.md` — adding a check
needs a triggering fixture *and* a near-miss false-positive control.

## Development

```bash
pip install -e ".[dev]"
pytest --cov=envcert
ruff check envcert tests
mypy envcert
python -m build
```

## Licence

Apache-2.0. Research and design rationale: `docs/research/`,
`docs/architecture/`. Release history: `CHANGELOG.md` and GitHub Releases.
Future work is tracked in GitHub Issues.
