Socket Python CLI for Socket scans, diff reporting, reachability analysis, and SARIF/GitLab exports.
Comprehensive docs are available in docs/ for full flag reference, CI/CD-specific guidance, and contributor setup.
Quick start
1) Install
pip install socketsecurity
2) Authenticate
export SOCKET_SECURITY_API_TOKEN="<token>"
The token needs more than scan-creation access. Most missing scopes fail the run, and
a token without the diff-scans scopes falls back with only a warning. See
docs/troubleshooting.md#api-token-permissions.
3) Run a basic scan
socketcli --target-path .
Common use cases
This section covers the paved path/common workflows.
For advanced options and exhaustive details, see docs/cli-reference.md.
For CI/CD-specific guidance, see docs/ci-cd.md.
By default, PR scans are diffed against the repository's latest matching head scan. To
prefer the commit your PR branched from as the baseline, pass the merge base:
The CLI uses the exact commit's newest matching full scan when one exists. Otherwise, it
searches up to 100 first-parent commits in the local checkout and uses the nearest scanned
ancestor, with a warning that the diff is wider than the merge base. Run socketcli
regularly on your default branch and ensure PR checkouts contain enough history for that
walk. The run fails with the configured API-error exit code only when no scanned ancestor
is reachable (or when the scan lookup itself fails). See
for the full behavior and an optional exact-baseline backfill pattern.
Successful report, skipped SCM event, or --disable-blocking set; findings gate only evaluated diffs
1
Blocking security finding(s) detected
2
Invalid flags or configuration (usage error), including argparse's own errors
3
Infrastructure or API error: missing API or SCM token, permission or plan problem, timeout, network failure, incomplete scan comparison, unexpected error
130
Scan interrupted (SIGINT / Ctrl+C)
--exit-code-on-api-error <N> remaps the infrastructure-error code (3) to any
value — e.g. a Buildkite
soft_fail
code, or 0 to swallow infra errors. Exit 3 is a Socket convention, not an
industry standard.
This mapping applies to errors the CLI receives and handles. An external process
supervisor (for example GNU timeout) can terminate the CLI before it handles an
error, so the supervisor's exit status (commonly 124 or 137) takes precedence.
How these options interact
The two flags that affect exit codes can cancel each other out, so the order of
precedence matters:
--disable-blocking forces exit 0 for findings, infrastructure errors and
interrupts. It takes precedence over --exit-code-on-api-error and
--strict-blocking. Usage errors still exit 2.
--exit-code-on-api-error only applies when --disable-blocking is not
set. It changes the infrastructure-error code, including unexpected runtime
failures. Findings (1), usage errors (2) and Ctrl+C (130) keep their codes.
So for the common "don't let Socket outages block my pipeline, but still fail on
real findings" goal, use --exit-code-on-api-errorwithout--disable-blocking:
# Buildkite: soft-fail only on infrastructure errors, still block on findings
steps:
- label: ":lock: Socket Security Scan"
command: "socketcli --exit-code-on-api-error 100 ..." # NOT --disable-blocking
soft_fail:
- exit_status: 100
Combining --disable-blocking with --exit-code-on-api-error 100 would make the
scan exit 0 on both findings and outages — the soft_fail: 100 rule would
never match, and real findings would stop blocking. That's usually not what you
want.
Upgrading from 2.12 or earlier
2.13 and 2.14 change exit codes and what --strict-blocking checks:
Exit codes: invalid flags or configuration exit 2, Ctrl+C exits 130,
and setup failures such as a missing token use the infrastructure-error code
(3 by default). Blocking findings still exit 1. See
Exit codes in CI.
Config files are validated before credentials or network setup. Use native
JSON/TOML booleans, a positive integer timeout and an array for files.
--strict-blocking fails on existing Block alerts, counts each advisory
separately, and compares code-only changes too, so pipelines can fail on
alerts they used to pass. Without --scm github or --scm gitlab, that
includes default-branch pushes, which need the full-scans:list and
repo:list token scopes; see
API token permissions.