Safeguard
Security Guides•

Is static analysis safer than running tests on untrusted code?

Static analysis reads code without running it; tests and builds execute it. How to choose what to run first on fork pull requests and in what sandbox.

Safeguard Security Team
3 min read

Generally yes, because static analysis reads source without executing it, while builds and tests run the contributor's code on your runner. Still, treat both as untrusted: run them with no secrets, a read-only token and a clean hosted runner, and do the cheap read-only checks first.

Definitions

Static analysis inspects source code, configuration or dependency manifests without running the program. Dynamic work such as builds, tests and install scripts executes code supplied by the contributor.

Why the difference matters

Executing code means the contributor's code controls the machine for the length of the job. Install hooks, test files, build scripts and Makefiles are all code. A scanner that parses files does not hand control to the contributor in the same way, though a scanner can still have its own bugs. Treat them as software that can have flaws too.

So even static tools should run in the same restricted setup.

A staged order of checks

StageCheckExecutes contributor code?
1Diff review, CODEOWNERS pathsNo
2Dependency manifest review and advisory checkNo
3Static code analysisNo
4Build and unit tests, no secretsYes
5Integration tests with credentials, after approvalYes

Cheap, non executing checks come first. If they fail, you never need to run the rest. Many maintainers also want stage 4 to wait for approval on first time contributors, which GitHub supports for public repositories.

The restricted setup

  1. Trigger on pull_request, so a fork gets no secrets and a read-only token.
  2. Use GitHub-hosted runners. GitHub says self-hosted runners should almost never be used for public repositories.
  3. Set a short job timeout and limit network egress where you can.
  4. Do not restore caches from privileged jobs into untrusted ones.
  5. Upload results as artifacts and report in a separate trusted workflow.

Do not forget dependency install scripts

Even a "static" workflow often runs a package install first. That runs install hooks of every dependency. If you just need the manifest, parse the manifest rather than installing.

When dynamic testing is worth it

Tests prove behavior, and an outside contribution that breaks the build is something you need to know. The point is not to avoid running tests, but to run them where a bad test can just waste minutes.

Try it yourself

Click through it at your own pace, or open it full screen.

Look at how findings are reported from reading code, without running the application.

Where Safeguard fits

Safeguard offers dependency scanning, SBOM and policy gates on pull requests, and reachability analysis. Try the free scan first.

Quick check

Is a scanner immune to a malicious repository?

No. Tools can have bugs when parsing untrusted input, so run them in a restricted job as well.

Should tests run before approval for a first time contributor?

On public repositories GitHub can hold those runs for maintainer approval. Review the diff, then approve.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.