Pre-run verification for untrusted code
v0.0.4 · alpha · available on PyPICheck the code before you run it.
SafeRun inspects AI-generated and downloaded projects inside a locked-down, offline container, and gives you a PASS, WARNING or FAIL verdict, without executing the program you submitted.
pip install saferun-cli- workspace-sensitive-files
- python-syntax
- python-static-analysis
- dependency-vulnerabilities
- hardcoded-secrets
- hidden-characters
- suspicious-files
One verdict, no execution.
Code goes in, passes through an isolated analyzer, and a report comes out. Your project is read, never run.
- Your code is never runStatic checks only: nothing you submit is executed.
- Scans work offlineNo network inside the analyzer container.
- Locked-down containersSandbox isolation: read-only copy, non-root, no capabilities.
- Pinned analyzer imageA cosign-signed image pinned by digest (built from a hash-locked recipe), locked locally and re-checked before every scan.
$ saferun status✓ python image pinned by digest✓ analyzer locked, labels verified✓ osv-db integrity manifest ok $ saferun scan ./my-projectVerdict: FAIL Scan complete: yesChecks: passed python-syntax passed hardcoded-secrets findings dependency-vulnerabilitiesFindings: [HIGH] demo-advisory requirements.txt$ echo $?101
Running unknown code is a leap of faith.
Code from an AI assistant, a forum or a download usually gets run first and read second.
Without a check
- An install script or import can run as soon as you try the project.
- Credential-like files travel with the folder.
- Dependencies may carry known vulnerabilities nobody looked up.
- A syntax error is found only when it crashes.
- Invisible characters can make code do something other than what it shows.
With SafeRun
- Static verification only: syntax checks and analyzers read the files, they do not run your program.
- Credential-like files are withheld from the analysis and the sandbox.
- Lockfile dependencies are matched against a local vulnerability database.
- Hidden characters, look-alike names and disguised programs are flagged.
- One normalized report and a verdict, with an exit code for scripts.
SafeRun checks what it can check. A passing scan lowers risk; it is not proof that code is safe.
02
From folder to verdict.
A fixed pipeline, run locally by the CLI.
- 01
Project
A folder on your machine.
- 02
Validation
The project is copied read-only; sensitive files are withheld; limits are enforced.
- 03
Isolated analyzer
Checks run in a verified container with no network. Nothing from the project is executed.
- 04
Security report
Each check is reported as passed, findings, or a coverage gap. Incomplete scans never report PASS.
03
Security you can inspect.
Each control below is implemented in the repository and documented with its limits.
- Your project is never executed
- It is copied read-only into a throwaway container: no network, non-root user, no Linux capabilities, memory, CPU and process limits.
- Images are pinned by digest
- An image is trusted only if Docker reports the exact pinned digest. A tag that merely exists is not enough.
- The analyzer is a signed, digest-pinned image
- Setup checks its cosign signature (this project's release workflow, a release tag) and the pinned digest before pulling it, then verifies its tool versions and rules hash. A signature would not prove the project itself was never compromised. You can build it yourself with --build-local instead.
- The analyzer is locked
- Its image ID, tool versions and rules hash are re-checked before every scan. The lock file must be private to your user.
- Vulnerability data has an integrity record
- SHA-256, size, advisory count and date are re-checked before every scan. Damaged, tampered or old data cannot produce PASS.
04
What it checks.
Python only
SafeRun checks Python code and Python dependencies. JavaScript and npm files are not checked, and a note in the report says so.
Can the scanner read it?
The syntax check parses every .py file without running it. A file that fails to parse is reported, because the other checks cannot analyse it.
Static analysis
Semgrep with SafeRun’s bundled Python rules, including rules for credential-file reads, persistence setup and hidden function lookups.
Hardcoded secrets
gitleaks inside the offline analyzer container. Secret values are never printed or logged: only the rule, file and line.
Dependency scanning
OSV-Scanner against local data. Each finding says whether the nearest fix is a patch, minor or major upgrade, and you can record an accepted risk with a reason and expiry date.
Hidden characters and disguised files
Flags invisible and direction-changing characters that make code read differently than it runs (“Trojan Source”), names written with look-alike letters that Python reads as another name (such as eval), programs disguised as images or text, native libraries, archives and auto-run .pth files. Archives are not opened.
Plain-English findings
Each finding in the report has an “In plain words” line: what it is, why it matters and how to fix it.
Package-name check
saferun check-names flags dependency names that resemble popular PyPI packages (reqeusts for requests). It is a separate command; scan is unchanged.
CLI first
saferun scan only reads files; saferun run scans a script (also one piped in with curl … | saferun run -) and runs it in the sandbox only if the verdict allows. Text, JSON or SARIF output, exit codes 0 PASS, 1 FAIL, 2 WARNING.
05
Read a report at a glance.
Pick a verdict to see how a report looks.
Verdict: WARNING
Minor findings, or a check could not run (missing or outdated component).
| Status | Check | Result |
|---|---|---|
| passed | python-syntax | No findings |
| passed | hardcoded-secrets | No findings |
| passed | python-static-analysis | No findings |
| unavailable | dependency-vulnerabilities | OSV data is missing: run saferun osv-db update |
Sample data. Real reports come from saferun scan.
06
Install from PyPI, then three commands.
SafeRun 0.0.4 is published on PyPI as saferun-cli (it installs the saferun command). Needs Python 3.12+ and Docker running Linux containers; works on Linux, Windows and macOS.
pip install saferun-cliAlso works with pipx install saferun-cli and uv tool install saferun-cli. To upgrade later: pip install --upgrade saferun-cli, then run saferun init again (it skips what is already valid).
- Ubuntu / LinuxFully tested
The full test suite, including the Docker sandbox and analyzer tests, runs locally and in CI.
- Windows 10/11Native, partly verified
A native implementation (no WSL needed for SafeRun itself). Non-Docker tests pass in CI on windows-2022; Docker Desktop integration has not yet been manually verified.
- macOSPartly verified
Same code as Linux. Non-Docker tests pass in CI on Apple Silicon and Intel; Docker Desktop integration has not yet been manually verified.
Set up
saferun initRun saferun init once. It checks Docker and installs only what is missing, verifying each part.
Diagnose
saferun doctorA read-only check that reports PASS, WARNING or FAIL per part, with the fix for each problem.
Scan or run
saferun scan ./my-projectScan a project folder (saferun scan alone scans the folder you are in), or scan a Python script and run it only inside the sandbox if the scan allows it.
Alpha release. SafeRun is alpha software and has not been independently certified or security-audited. A PASS means the existing checks found nothing, not that the code is safe.
Platform-specific setup for Ubuntu/Linux, Windows and macOS →
Open source, on GitHub.
Read the code, the threat model and the documented limits. Issues and feedback are welcome.
07
Questions, answered.
How do I install it?
Run pip install saferun-cli (version 0.0.4 is on PyPI; pipx and uv tool work too), then saferun init and saferun doctor. The setup guide has every command, with copy buttons.
Is it production-ready?
SafeRun is alpha software and has not been independently certified or security-audited. A PASS means the existing checks found nothing, not that the code is safe.
Which platforms are supported?
Ubuntu/Linux is fully tested. Native Windows and macOS are supported but only partly verified: their non-Docker tests pass in CI, while Docker Desktop integration has not yet been manually verified. The guide has a section for each.
Why does it need Docker?
A local Docker Engine that your user can reach, with memory, swap, pids and CPU limits and seccomp enabled. Remote Docker endpoints are refused. On Windows and macOS use Docker Desktop in Linux containers mode: that integration has not yet been manually verified.
Do I need Cosign?
Nothing to install. If you have no cosign, saferun init fetches a pinned release from github.com into its own data directory and keeps it only if its SHA-256 matches the value written in SafeRun's source. It then verifies the signed analyzer image before anything is pulled. With --build-local no cosign is needed.
Does it need internet access?
Only for setup (Docker Hub, the signed analyzer from ghcr.io with its Sigstore check, github.com to fetch cosign if you have none, and the OSV data; a local analyzer build uses PyPI and GitHub instead), and for two opt-in commands: saferun run --install-deps fetches packages from PyPI and saferun check-names --online looks names up on pypi.org. Scans never use the network.
Which languages are supported?
Python only: the syntax check, Semgrep rules, the secrets scan and the dependency scan for Python projects. JavaScript and npm files are not checked; a note in the report says so, and it does not change the verdict.
What is the difference between scan and run?
saferun scan only reads the files and reports; no project code is run. saferun run scans a Python script first and runs it, inside the sandbox only, when the verdict allows it.
Can saferun run use a script that needs packages?
Yes, if you ask for it: saferun run --install-deps fetches the packages the script declares (or that you name with --with) from PyPI as wheels only, so no install script runs. Every installed package is checked against the offline vulnerability data, and the names you asked for are checked for look-alikes of popular PyPI names, before the script runs. The packages are mounted read-only in the sandbox. The code inside the packages is not checked.
Can I see the results in GitHub code scanning?
saferun scan --format sarif writes a SARIF 2.1.0 file with the same verdict and exit code. Uploading it to GitHub code scanning has not been tried yet. A list of alerts shows an incomplete scan as if it were clean, so the verdict and exit code are what count.
Does it look for hardcoded secrets?
Yes. gitleaks runs inside the offline analyzer container. Secret values are never printed, logged or put in the JSON report: only the rule, file and line. You can turn it off with --no-secrets-check, which limits the verdict to WARNING at best.
Does a PASS mean the code is safe?
Honest limits: these checks detect damage and later changes, but a locally recorded hash cannot prove the original download was genuine. PASS means the existing checks found nothing, not that the code is safe. Scans send nothing anywhere and are only as current as your last saferun osv-db update.