Skip to main content
Use safedep query exec to ask your SafeDep Cloud tenant about its projects, packages, endpoints, events, and findings. For the full query rules, see the SafeDep Cloud SQL reference.

Prerequisites

Install the CLI and sign in to SafeDep Cloud:
SafeDep scopes every query to your tenant. You never write a tenant filter yourself.

Your first query

Start by seeing what you can query. List the tables, then inspect one to view its columns, capability flags, and join edges:
See Discovering the schema for the full set of schema commands. Now run a query. It is mostly SQL. Select some columns, filter with WHERE, sort with ORDER BY:
Two things make this different from a generic database:
  1. Write every column as table.column using the real table name. No table aliases, no bare column names. Result aliases via AS work (COUNT(...) AS n, then ORDER BY n).
  2. Every query must filter on an indexed column or a bounded time range. Here projects.origin_source is indexed, so the query is accepted. This rule keeps queries cheap; the schema marks which columns are indexed.
safedep query exec reads the statement from --sql, --sql-file, or stdin:

Letting an AI agent write the queries

Point your AI coding agent at the safedep CLI. The schema is self-describing and server errors come back verbatim, so the agent can discover tables, write a query, and self-correct on its own. Prompt:

Examples

Anchor on the indexed ecosystem column (an OR across all severities would not satisfy the index rule):
EPSS is join-only enrichment, so anchor in the tenant packages table and join out. Sorting by EPSS surfaces the CVEs most likely to be exploited:
kev is the CISA Known Exploited Vulnerabilities catalog. Use a bounded range on the indexed kev.date_added to anchor the query:
is_malware is not indexed, so anchor on the indexed detected_at timestamp:
Walk from packages through component_licenses to the global licenses catalog for SPDX metadata. Anchor on the indexed packages.ecosystem:
endpoints are the machines and CI runners reporting to your tenant. The timestamp columns are indexed, so a bounded range anchors the query:
The endpoint_type and trust_level enums are not groupable, so use WHERE filters and listings rather than GROUP BY for endpoints. SafeDep Cloud does not set endpoint_type yet, so every endpoint shows 0. To find CI events, filter on package_guard_events.ci_provider IS NOT NULL.
For “which endpoints…” questions you want a de-duplicated list, not one row per event, so use SELECT DISTINCT:
Join Package Guard events to the endpoint that produced them, newest first, for a full audit trail:
The package_ecosystem enum renders as its stored number in table output (2 = ECOSYSTEM_NPM, 3 = ECOSYSTEM_PYPI); use -o json for the enum name.
inventory_events captures items discovered by vet on each endpoint. Filter on the indexed item_kind to find AI-related items:

SafeDep Cloud SQL

Tables, supported SQL, schema flags, output modes, and errors.

Investigate with an AI Agent

Ask questions in plain English and let an agent write the SQL.