Ubuntu / Linux
Fully tested
The full test suite, including the Docker sandbox and analyzer tests, runs locally and in CI.
Version 0.0.4 · alpha · PyPI · GitHub Releases
SafeRun checks code before you run or trust it, without ever running it. Setup installs only what each check needs, and verifies it.
Install SafeRun 0.0.4 from PyPI (in a virtual environment or with pipx):
pip install saferun-cliThen:
Run saferun init once. It checks Docker and installs only what is missing, verifying each part.
saferun initA read-only check that reports PASS, WARNING or FAIL per part, with the fix for each problem.
saferun doctorScan 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.
saferun scan ./my-projectNeeds Python 3.12+, a local Docker that runs Linux containers and internet access for setup. First install it with pip install saferun-cli (details per platform under Full setup below).
SafeRun runs on Ubuntu/Linux, native Windows and macOS. Every platform needs a local Docker that runs Linux containers; installing SafeRun does not install Docker.
Fully tested
The full test suite, including the Docker sandbox and analyzer tests, runs locally and in CI.
Native, 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.
Partly 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.
Docker Desktop integration on Windows and macOS has not yet been manually verified. CI cannot run Linux containers on those systems, so the sandbox and analyzer tests there were not run.
| Ubuntu / Linux | Windows | macOS | |
|---|---|---|---|
| Docker | Docker Engine | Docker Desktop, Linux containers | Docker Desktop, Linux containers |
| Analyzer image | linux/amd64, native | linux/amd64 (emulated on ARM) | linux/amd64 (emulated on Apple Silicon) |
| Per-user data | ~/.local/share/saferun | %LOCALAPPDATA%\saferun | ~/Library/Application Support/saferun |
| Special files | Symlinks are never followed | Symlinks, junctions and alternate data streams are skipped and reported | Symlinks are never followed |
| Private files | Withheld unless world-readable | Withheld unless everyone who can read the project can read them | Withheld unless world-readable |
| Verification | Full suite including Docker tests | Non-Docker tests in CI; Docker Desktop not yet manually verified | Non-Docker tests in CI; Docker Desktop not yet manually verified |
Windows: the project and the temp folder must be on a local drive shared with Docker Desktop; Windows containers mode is refused. Details: platform status.
New to this? Choose your platform, then follow the steps in order. Each command can be copied with its button.
Debian and Ubuntu commands. Other distributions use their own package names.
Check what you have. If it is older than 3.12, install a newer one with your package manager.
python3 --versionsudo apt install python3 python3-venv python3-pipThe apt line is for Debian and Ubuntu; other distributions have their own package names. The venv package is needed for the next steps.
Docker downloads the images and runs every check in a locked-down container. Follow the official instructions for your distribution, then make sure the daemon runs and your user may use it.
docker --versionsudo systemctl enable --now dockersudo usermod -aG docker $USERdocker infoOfficial instructions: https://docs.docker.com/engine/install/. After usermod, log out and back in. Members of the docker group have root-equivalent access to the machine, so add only users you trust. docker info must print without an error.
SafeRun 0.0.4 is published on PyPI as saferun-cli; it installs the saferun command. Use a virtual environment (or pipx). Semgrep and OSV-Scanner are not installed on your computer: they live in the analyzer image.
python3 -m venv ~/saferun-envsource ~/saferun-env/bin/activatepip install saferun-clisaferun --versionActivate the virtual environment in every new terminal. pipx install saferun-cli and uv tool install saferun-cli work too. On Debian and Ubuntu, pip refuses to install into the system Python (externally managed environment), so use the virtual environment or pipx.
Installs only what is missing, and verifies each part before trusting it. It pulls the Python image by pinned digest, fetches a hash-verified cosign for itself if you have none, checks the signed analyzer image (signature first, then the exact pinned digest from ghcr.io, about 740 MB), and downloads the OSV vulnerability data (about 36 MB).
saferun initYou do not install cosign yourself. Run saferun init --all for no questions (scripts, CI). To build the analyzer from the repository recipe instead (a few minutes, needs a source checkout), see the commands list: saferun init --only analyzer --build-local.
A read-only check: PASS, WARNING or FAIL for Python, Docker, the images, the analyzer, cosign and the OSV data, with the fix for each problem. Exit code 0 when nothing failed.
saferun doctorsaferun statussaferun status lists the components and exits 0 only when all are ready.
Scans a local folder. Nothing in it is executed, and the scan needs no network.
saferun scan ./my-projectInside the project folder, saferun scan alone scans the folder you are in (it prints the full path). Exit codes: 0 PASS, 1 FAIL, 2 WARNING (including any incomplete scan), 64 bad usage, 70 fatal error.
Scans the script first and runs it only inside the hardened sandbox (no network, read-only, non-root, resource limits) if the scan allows it. A FAIL or WARNING is refused.
saferun run my_script.pyPut saferun options before the script name. A PASS is not proof the script is safe; the sandbox limits its impact. Scripts that need the network fail inside it; for third-party packages add --install-deps (see Commands).
Optional: repeat the signature check whenever you like. It needs internet and cosign.
Repeats the signature check of the recorded analyzer release (analyzer-v1.2.0) on demand, online and with cosign (SafeRun uses its own verified copy or one on your PATH). The pinned Python image is checked as well.
saferun verify-images --signatureExpect VERIFIED on the cosign line and "all pinned images verified" at the end. Anything else prints NOT VERIFIED: do not rely on the images.
pythonRuns the Python syntax check, the hidden-character and suspicious-file checks, and the scripts you start with saferun run, in a locked-down container.
~190 MB
Python syntaxHidden charactersSuspicious filesRun in sandbox
analyzerHolds Semgrep, its rules, OSV-Scanner and gitleaks. Runs the static code analysis, the secrets scan and the dependency scan.
~740 MB, signed download
Static analysisSecrets scanDependency scan
osv-dbLocal vulnerability data, so dependency scans run offline.
~36 MB download
Dependency scan
Nothing to do.saferun init --only <name>saferun init --only <name> (analyzer: add --repair)saferun osv-db update (analyzer: saferun init)saferun initShows what is installed and verified, asks what to install. Press Enter for everything.
saferun init --allAdd --yes to confirm prompts automatically.
saferun init --only python,analyzerNames: python, analyzer, osv-db.
saferun init --skip osv-dbUse this if you do not need dependency scanning.
saferun init --only analyzer --repairReplaces the analyzer image and its lock with a fresh install (the signature-checked release, or a local build with --build-local). Only when status says INVALID.
saferun init --only analyzer --build-localBuilds it from the repository recipe instead of installing the signed download. Needs a SafeRun checkout and internet for PyPI and GitHub, not cosign. Never done automatically.
saferun verify-images --signatureOnline, needs cosign: confirms the recorded release is signed by this project's release workflow and names the pinned digest. Exit code 1 on any failure.
saferun scanThe same as saferun scan . : the full path of the folder is printed on stderr and in the report header.
saferun scan . --format sarif > saferun.sarifSARIF 2.1.0 with the same verdict and exit code as --format json. A viewer that lists alerts only shows an incomplete scan as clean, so check the exit code. Uploading to GitHub code scanning has not been tried yet.
saferun scan ./my-project --accept-file ~/saferun-accepts.tomlEach [[accept]] entry needs an id, a reason and an expiry date. The file is never read from the scanned project. Accepted findings stay listed but leave the verdict; after the expiry date they count again.
saferun scan ./my-project --no-secrets-checkThe check is reported as skipped, which makes the verdict WARNING at best. Secret values are never printed: only rule, file and line. --no-hidden-characters and --no-suspicious-files work the same way.
saferun check-names --project ./my-projectA separate command: scan and run never do this check. Add --online to look names up on pypi.org (names only are sent).
saferun scan ./my-project --color neverColours, icons and the spinner appear only on a terminal; --format json is always plain. NO_COLOR is honoured.
saferun doctorPASS, WARNING or FAIL per check, with the fix for each problem. Exit code 1 if anything failed. --online also re-verifies the release signature; --format json for tools.
saferun run my_script.pysaferun scan only reads files; run scans first, then executes in the sandbox. Refused on FAIL (exit 1) or WARNING (exit 2); --allow-warnings accepts a WARNING only from a complete scan with no high or critical finding. Exit 3: the script ran but failed or timed out. Options go before the script name.
curl -fsSL URL | saferun run -Use it instead of curl … | python. SafeRun reads the whole script first (at most 5 MB), prints its size and SHA-256, and scans and runs that one copy in the sandbox. Use curl -f so an HTTP error sends nothing.
saferun run --install-deps my_script.pyInstalls the packages the script declares (a # /// script block) or that you add with --with NAME, from PyPI, as wheels only, with pip on your computer; no package code runs there. Every installed package is checked against the offline OSV data, and the requested names for look-alikes of popular PyPI names; then they are mounted read-only in the sandbox. The code inside the packages is not checked.
saferun cleanupLists old analyzer images, OSV data SafeRun no longer uses and leftovers of crashed runs, then asks before removing them (--yes in scripts). Never touches the current analyzer or the python image.
saferun statusExit code 0 only when everything is ready. Add --format json for scripts.
saferun osv-db updateDownloads the OSV data. Sends nothing about your project.
saferun osv-db update --if-staleDownloads only when the data is missing, invalid or older than 30 days. Run it daily from cron or Task Scheduler (examples in the CLI reference).
saferun osv-db statusOlder than 30 days makes the dependency check incomplete. From day 25, scan, status, doctor and this command warn.
| Check | Needs |
|---|---|
| Python syntax (can the scanner read this file?) | python |
| Static analysis (Semgrep) | analyzer |
| Hardcoded secrets (gitleaks) | analyzer |
| Dependency vulnerabilities | analyzer + osv-db |
| Hidden characters (invisible, direction-changing and tag characters, look-alike names) | python |
| Suspicious files (programs, native libraries, disguised files, archives, auto-run files) | python |
SafeRun is Python-only: JavaScript files are not checked and npm lockfiles are not scanned (the report says so, and it does not change the verdict). Not installed on purpose: Semgrep, OSV-Scanner and gitleaks never run on your computer, only inside the analyzer container. Running your tests is not available. Packages are installed only for saferun run --install-deps (online, opt-in), never for a scan.
Every check ran and found nothing.
Looks fine, but it is not a proof of safety.
Minor findings, or a check could not run (missing or outdated component).
Run saferun status, apply the fix, scan again.
At least one high or critical finding.
Do not run the project until it is fixed.
Install Docker Engine and start it (sudo systemctl enable --now docker). docker info must work for your user. SafeRun only uses a local daemon and refuses remote ones.
Your user is not in the docker group, or the group change is not active yet. Run sudo usermod -aG docker $USER, then log out and back in.
Start Docker Desktop and make sure it runs Linux containers (on Windows: tray icon, Switch to Linux containers). docker info --format "{{.OSType}}" must print linux. Docker Desktop integration has not yet been manually verified, so please report what you see.
Keep the project on a local drive that Docker Desktop shares. Windows: network (UNC) and \?\ paths are refused. macOS: /Users is shared by default; with Colima or Lima set TMPDIR to a shared folder.
Nothing was installed or pulled. Install cosign 2.2 or newer yourself (https://docs.sigstore.dev/cosign/system_config/installation/), put it on your PATH, and run saferun init --only analyzer again. Or build the analyzer yourself with saferun init --only analyzer --build-local.
Docker does not report the pinned digest for it (for example a tag that moved or an image loaded without its digest). Run saferun init --only python to pull the pinned one. Do not ignore an INVALID analyzer: see the --repair entry above.
Run saferun status. It names the component and prints the exact fix, for example saferun init --only osv-db. A scan also prints that fix on stderr.
Images are repaired by pulling the pinned digest. The analyzer is reinstalled only with --repair, because that replaces the image and its lock. Investigate first if you did not expect it.
Read the fix printed under that line and run it, then run saferun doctor again. It changes nothing itself. Add --online to also re-verify the signature of the published analyzer release.
Nothing was pulled or trusted. Check your internet access to ghcr.io and sigstore.dev, then retry. If it keeps failing, do not use --build-local to get around it without finding out why.
The new SafeRun version pins newer analyzer tools or rules. Run saferun init: it replaces the analyzer (no --repair needed) and then removes the old image if no container uses it. Scans never use an outdated analyzer. saferun cleanup removes other old images.
The OSV data is older than 30 days. Run saferun osv-db update. Until then findings are still shown, but the result can never be PASS.
Setup needs Docker Hub, ghcr.io and sigstore.dev (signed analyzer; a local build needs PyPI and GitHub instead) and the OSV download once. Without them it keeps what is already valid and lists what is missing. See Working offline below; the analyzer cannot be installed on a machine that never has internet.
A check whose component is missing is reported, never skipped, and SafeRun never falls back to tools installed on your computer.
It is copied read-only into a throwaway container: no network, non-root user, no Linux capabilities, memory, CPU and process limits.
An image is trusted only if Docker reports the exact pinned digest. A tag that merely exists is not enough.
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.
Its image ID, tool versions and rules hash are re-checked before every scan. The lock file must be private to your user.
SHA-256, size, advisory count and date are re-checked before every scan. Damaged, tampered or old data cannot produce PASS.
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.