Set up SafeRun in three steps

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.

  • Your code is never run
  • Scans work offline
  • Locked-down containers
  • Pinned analyzer image

Quick start

Install SafeRun 0.0.4 from PyPI (in a virtual environment or with pipx):

pip install saferun-cli

Then:

  1. Set up

    Run saferun init once. It checks Docker and installs only what is missing, verifying each part.

    saferun init
  2. Diagnose

    A read-only check that reports PASS, WARNING or FAIL per part, with the fix for each problem.

    saferun doctor
  3. Scan or run

    Scan 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-project

Needs 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).

Platforms

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.

Ubuntu / Linux

Fully tested

The full test suite, including the Docker sandbox and analyzer tests, runs locally and in CI.

Windows 10/11

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.

macOS

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.

How it works across platforms

One shared core
The sandbox policy, the preflight, the signature check and the verdict logic are the same on every platform.
One place that knows the OS
Only the host layer (saferun/hostos/) branches on the platform: file copying, locks, permissions and process cleanup.
Linux containers everywhere
Untrusted code never runs on your computer. On Windows and macOS the checks run in Linux containers through Docker Desktop.
Fails closed
Where a safe copy or a security check cannot be done on a platform, SafeRun withholds the file or refuses to run and says so in the report.

Differences and limitations

Ubuntu / LinuxWindowsmacOS
DockerDocker EngineDocker Desktop, Linux containersDocker Desktop, Linux containers
Analyzer imagelinux/amd64, nativelinux/amd64 (emulated on ARM)linux/amd64 (emulated on Apple Silicon)
Per-user data~/.local/share/saferun%LOCALAPPDATA%\saferun~/Library/Application Support/saferun
Special filesSymlinks are never followedSymlinks, junctions and alternate data streams are skipped and reportedSymlinks are never followed
Private filesWithheld unless world-readableWithheld unless everyone who can read the project can read themWithheld unless world-readable
VerificationFull suite including Docker testsNon-Docker tests in CI; Docker Desktop not yet manually verifiedNon-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.

Full setup, step by step

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.

What you need

Operating system
Linux (Ubuntu), native Windows 10/11 or macOS. The analyzer image is linux/amd64 only, so on Apple Silicon and Windows ARM it runs under emulation.
Python
3.12 or newer, with venv and pip.
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.
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.
Internet
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.
Disk space
About 1.5 GB for images and vulnerability data.
  1. Install Python 3.12 or newer

    Check what you have. If it is older than 3.12, install a newer one with your package manager.

    python3 --version
    sudo apt install python3 python3-venv python3-pip

    The apt line is for Debian and Ubuntu; other distributions have their own package names. The venv package is needed for the next steps.

  2. Install Docker Engine and start it

    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 --version
    sudo systemctl enable --now docker
    sudo usermod -aG docker $USER
    docker info

    Official 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.

  3. Install SafeRun from PyPI

    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-env
    source ~/saferun-env/bin/activate
    pip install saferun-cli
    saferun --version

    Activate 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.

  4. Set SafeRun up

    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 init

    You 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.

  5. Diagnose the installation

    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 doctor
    saferun status

    saferun status lists the components and exits 0 only when all are ready.

  6. Run your first scan

    Scans a local folder. Nothing in it is executed, and the scan needs no network.

    saferun scan ./my-project

    Inside 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.

  7. Run a Python script safely

    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.py

    Put 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).

Verify the signed analyzer release

Optional: repeat the signature check whenever you like. It needs internet and cosign.

  • Verify the analyzer signature yourself

    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 --signature

    Expect VERIFIED on the cosign line and "all pinned images verified" at the end. Anything else prints NOT VERIFIED: do not rely on the images.

How the pieces fit together

Docker downloads and runs the images
Setup uses it to pull images. Every scan then runs inside containers without network access, with your project mounted read-only.
Cosign verifies the signed analyzer
Setup gets a hash-verified cosign for itself if you have none. Cosign checks the analyzer's signature against this project's release workflow and a release tag before the image is pulled, and the image must match the digest recorded in SafeRun. There is no unsigned download. A signature does not prove the project itself was never compromised. Whichever way it is installed, the analyzer is then locked locally.
The Python image is pinned by digest
It is trusted only if Docker reports exactly the digest in SafeRun's source. A tag that merely exists is not enough. It is not cosign-checked; the digest is its anchor.
Normal scans run without network
Setup is the only step that needs the internet (plus saferun osv-db update later, and the opt-in saferun run --install-deps, which downloads packages from PyPI). After it, scans work offline against the local OSV data.

What gets installed, and why

python

Python sandbox image

Runs 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

analyzer

Analyzer image

Holds 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-db

OSV vulnerability database

Local vulnerability data, so dependency scans run offline.

~36 MB download

Dependency scan

What the status of each part means

READYInstalled and verified just now.Nothing to do.
MISSINGNot installed.saferun init --only <name>
INVALIDPresent but failed verification (wrong digest, changed lock, damaged data).saferun init --only <name> (analyzer: add --repair)
OUTDATEDOSV data older than 30 days, or an analyzer image from an older SafeRun release (scans do not use it).saferun osv-db update (analyzer: saferun init)

Commands

  • Guided setup: pick components from a menu

    saferun init

    Shows what is installed and verified, asks what to install. Press Enter for everything.

  • Everything, no questions (scripts, CI)

    saferun init --all

    Add --yes to confirm prompts automatically.

  • Only some components

    saferun init --only python,analyzer

    Names: python, analyzer, osv-db.

  • Everything except some

    saferun init --skip osv-db

    Use this if you do not need dependency scanning.

  • Rebuild a failed analyzer

    saferun init --only analyzer --repair

    Replaces 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.

  • Build the analyzer locally

    saferun init --only analyzer --build-local

    Builds 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.

  • Check the analyzer signature

    saferun verify-images --signature

    Online, 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.

  • Scan the folder you are in

    saferun scan

    The same as saferun scan . : the full path of the folder is printed on stderr and in the report header.

  • Report for code scanning tools (SARIF)

    saferun scan . --format sarif > saferun.sarif

    SARIF 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.

  • Accept a dependency risk you have judged

    saferun scan ./my-project --accept-file ~/saferun-accepts.toml

    Each [[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.

  • Turn the secrets scan off

    saferun scan ./my-project --no-secrets-check

    The 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.

  • Look for look-alike package names

    saferun check-names --project ./my-project

    A separate command: scan and run never do this check. Add --online to look names up on pypi.org (names only are sent).

  • Plain output for logs and CI

    saferun scan ./my-project --color never

    Colours, icons and the spinner appear only on a terminal; --format json is always plain. NO_COLOR is honoured.

  • Diagnose the installation (read-only)

    saferun doctor

    PASS, 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.

  • Scan a script and run it only in the sandbox

    saferun run my_script.py

    saferun 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.

  • Scan and run a downloaded script

    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.

  • Run a script that needs packages (online)

    saferun run --install-deps my_script.py

    Installs 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.

  • Remove what SafeRun left behind

    saferun cleanup

    Lists 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.

  • See what is installed

    saferun status

    Exit code 0 only when everything is ready. Add --format json for scripts.

  • Update the vulnerability data

    saferun osv-db update

    Downloads the OSV data. Sends nothing about your project.

  • Keep the data fresh on a schedule

    saferun osv-db update --if-stale

    Downloads 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).

  • Check the data age and integrity

    saferun osv-db status

    Older than 30 days makes the dependency check incomplete. From day 25, scan, status, doctor and this command warn.

Which part powers which check

CheckNeeds
Python syntax (can the scanner read this file?)python
Static analysis (Semgrep)analyzer
Hardcoded secrets (gitleaks)analyzer
Dependency vulnerabilitiesanalyzer + 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.

Reading the verdict

PASS

Every check ran and found nothing.

Looks fine, but it is not a proof of safety.

WARNING

Minor findings, or a check could not run (missing or outdated component).

Run saferun status, apply the fix, scan again.

FAIL

At least one high or critical finding.

Do not run the project until it is fixed.

If something is missing or outdated

Setup says Docker is unusable, or docker: command not found (Linux)

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.

Docker says permission denied (Linux)

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.

Windows or macOS: SafeRun says it needs Linux containers, or Docker is unusable

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.

Windows or macOS: the project folder is refused or cannot be mounted

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.

Setup cannot fetch cosign (no pinned build for your CPU, or the download or its hash check failed)

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.

saferun status shows an image as INVALID

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.

A check says "unavailable", "error" or "incomplete"

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.

A component says INVALID

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.

saferun doctor reports a FAIL or WARNING

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.

Setup says the signature could not be verified

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.

After an upgrade, saferun status shows the analyzer as OUTDATED

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 dependency scan says incomplete

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 says there is no internet access, or you are offline

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.

Nothing is skipped silently

A check whose component is missing is reported, never skipped, and SafeRun never falls back to tools installed on your computer.

Working offline

  • After setup, scans never need the internet: the checks run in containers without network and read the local OSV data.
  • Without internet, saferun init uses what is already valid, skips downloads it does not need and lists what is missing.
  • It never reports dependency scanning ready without valid OSV data.

Preparing a machine without internet

OSV data
On a connected machine: saferun osv-db update --dir DIR. Copy DIR over and set SAFERUN_OSV_DB=DIR (or place it at the default location). Check with saferun osv-db status.
Sandbox images
docker pull on a connected machine, then docker save / docker load. SafeRun trusts a loaded image only if Docker still reports the pinned digest; otherwise status says INVALID.
Analyzer image
Cannot be installed without internet yet: the signed download needs ghcr.io, sigstore.dev and github.com for cosign (a local build needs PyPI and GitHub). Run saferun init --only analyzer once while online.

How SafeRun stays safe

  • 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.

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.

Releases, upgrading and reporting problems

Current release
SafeRun 0.0.4, published on PyPI as saferun-cli and as a GitHub release. Check yours with saferun --version.
Upgrading
Run pip install --upgrade saferun-cli, then saferun init (it skips what is already valid and replaces an outdated analyzer) and saferun doctor. A new analyzer image is a separate, signed release that SafeRun records and verifies by digest. saferun cleanup removes old images afterwards.
Status
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.
Reporting a vulnerability
Report privately through GitHub, not in a public issue. See the security policy.