locksql

module
v0.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: Apache-2.0

README

CI Latest release Go version

Let any AI agent query your SQL databases: personal data comes back masked,
connections and writes wait for you, and the agent never holds a password.

An agent (here Claude Code, left) and the locksql console (right). Recorded before approvals moved to lockhub: today you answer in lox run, and masked cells come back as plain <redacted>.

Quick start · How it works · Docs · Lock Family · locksql.com


locksql is a Lock of the Lock Family, harness security for AI agents. A console sits between your agent and MariaDB, MySQL, PostgreSQL or SQLite: it holds the credentials, weighs every statement and masks personal data. The agent only asks.

[!NOTE] Pre-release (v0.17.x): a release may still change the config files, the MCP tools or the CLI. See the path to 1.0.

Why locksql

  • The agent never holds a password. Credentials are typed at console start or read from Vault, in an account and a container the agent cannot reach.
  • Approval outside the agent. Each statement becomes a ticket on lockhub, decided in lox run. Reads pass on your rules; connections, writes and schema changes wait for you.
  • Personal data stays masked. Every output column is traced to its source column and masked there, whatever the query calls it.
  • Fail closed. What the classifier cannot classify with certainty is refused, with a code the agent can act on.

In-agent approval is a convenience; a separate approval process is a boundary.

Install

brew trust davidgodefroid/tap
brew install davidgodefroid/tap/lox davidgodefroid/tap/locksql

locksql runs in Docker: Homebrew installs the locksql launcher, which runs every command in the release's image. lox is lockhub's CLI. The whole family instead: brew install davidgodefroid/tap/lockfamily.

Without Homebrew, the signed install script of a release:

V=vX.Y.Z
curl -fsSLO "https://raw.githubusercontent.com/DavidGodefroid/locksql/$V/scripts/install.sh"
less install.sh
LOCKSQL_VERSION=$V sh install.sh

Linux and macOS; on Windows, WSL 2 with Docker Desktop. Launcher, image, Vault image, lea and building from source: docs/install.md.

Quick start

  1. In your project, add the database. lox add asks where it is (never the password), writes the profile, wires your agent and starts the console:

    lox add locksql
    
  2. In a terminal of its own, outside any agent, keep lox run open. Every ticket shows up there:

    lox run
    
  3. Start your agent in the project (claude, codex, gemini, …) and ask: "how many orders were placed yesterday?"

lox add wires Claude Code; for Codex, Cursor or Gemini CLI, also run locksql init codex (or cursor, gemini). With lea, run lox add in lea's projects directory, then lea stop and lea. Step by step, by hand: docs/install.md.

Highlights

🔑 One key holder
Credentials live in the console only: never in argv, env, files, logs, the socket or an error message.

👤 Your rules, your decisions
Per profile, each action is auto, ask or deny. By default reads pass; writes, DDL and unmasked reads are asked every time.

🕶️ PII masked at the source
Columns are traced through aliases, CTEs, unions and joins, then masked (redact, partial, email); detectors catch the rest.

⚖️ Weighed before it runs
LIMIT is mandatory, EXPLAIN runs first, and plans that would scan too many rows are refused.

More: OS separation, grants, writes, remote databases, and the console's switches.

How it works

Two processes in two containers. Only the console holds the key.

sequenceDiagram
    autonumber
    participant A as 🤖 AI agent<br/>(locksql mcp / CLI)
    participant C as 🔐 locksql console
    participant L as 🎫 lockhub (lox run)
    participant D as 🗄️ Database
    A->>C: plan "SELECT … LIMIT 20"
    C->>D: EXPLAIN
    C-->>A: plan id + verdict (OK / WARN / REFUSE)
    A->>C: run PLAN_ID
    C->>L: ticket, every literal masked
    C-->>A: pending, ticket T
    L-->>C: signed decision (your rule, or you)
    A->>C: run T
    C->>D: the statement
    C-->>A: masked, capped rows (untrusted data)
  1. The agent plans a statement (locksql plan, or the locksql_plan MCP tool). The console classifies it, traces every output column, runs EXPLAIN and answers with a verdict.
  2. The agent runs the plan. The console sends lockhub a ticket and answers pending.
  3. lox run decides, on your profile's rules or by asking you. The console checks the signed decision, runs the statement, masks and caps the rows.

Engines: MariaDB 10.1+, MySQL 8.0+, PostgreSQL 13+, SQLite 3, all pure Go, on amd64 and arm64. The approval screen, the process layout and the engines table: docs/architecture.md.

Safety model

  • The console is the enforcement point. Skills, rules and MCP tool descriptions only guide the agent; the console's checks are the guarantee.
  • OS separation. The console runs as its own account in its own container; the kernel checks every peer on the socket.
  • The AI tightens, the human loosens. Agents may add mask rules; any loosening of the policy waits for your confirmation in the console.
  • Audit. Every decision, refusal and run goes to an append-only JSONL log, never with secrets or row data.
  • Known limits. Masking is best effort, k-anonymity is a warning, and whoever can run docker commands can reach the console's container.

Every rule and limit: docs/safety.md. Threat model: docs/security-model.md.

Documentation

Doc What it covers
docs/install.md install paths, the launcher and its image, the first query by hand, building
docs/docker.md what runs where in Docker, Vault, an agent in its own container
docs/usage.md the console, client commands, MCP server, agent wiring, grants, auto mode
docs/configuration.md every profile key, TLS, SSH, PII rule sets, sharing a configuration
docs/console.md --allow-unmask, console keys, clear results (Ctrl-O)
docs/architecture.md the life of a query, the approval screen, engines
docs/safety.md the safety model and the limitations, in full
docs/security-model.md threat model, mitigations, upstream recommendation
docs/pii-analysis.md how the PII analysis works (for contributors)
docs/1.0.md the 1.0 criteria and the versioning policy
CHANGELOG.md what changed, release by release

The site, locksql.com, is built from site/.

The Lock Family

Repo What it does
lockfamily The family site (lockfamily.dev) and the one-line installer.
locksql SQL databases: the agent queries, PII comes back masked; connections and writes wait for you.
lockmq RabbitMQ: masked queue inspection; connections, peeks and unmasked reads wait for you.
lockfile Files (S3, SFTP, disk): the agent asks yes/no questions about files it never reads.
lockhttp Outbound HTTP(S): reads of trusted hosts pass; anything that sends data or reaches an unknown host waits for you.
locklog Logs: masked, bounded log search; the agent reads the logs, not the people in them.
lockssh Commands over SSH: allow-listed commands run at once, the rest waits for you; the key never leaves the console.
lockhub The approval hub and its lox CLI: lox run approves outside the agent's harness and never sees values in clear.
lockkit The shared Go core of every Lock: console, policies, masking, signed tickets, audit, MCP.
lea Runs many agents in containers, wired to the Locks.

Contributing · Security · License

  • Contributing: CONTRIBUTING.md. Build with CGO_ENABLED=0 go build ./cmd/locksql (Go 1.26+).
  • Security: report a vulnerability privately, see SECURITY.md.
  • License: Apache License 2.0, see LICENSE and NOTICE.

Directories

Path Synopsis
cmd
locksql command
Command locksql lets AI agents query databases only through a human-approved console.
Command locksql lets AI agents query databases only through a human-approved console.
internal
agentinit
Package agentinit implements `locksql init <agent>` and the user-scope wiring of bare `locksql` and `locksql doctor --fix`: it holds locksql's texts (templates/) and wires them through lockkit's agentwire, which owns the file mechanics.
Package agentinit implements `locksql init <agent>` and the user-scope wiring of bare `locksql` and `locksql doctor --fix`: it holds locksql's texts (templates/) and wires them through lockkit's agentwire, which owns the file mechanics.
client
Package client is the secret-free side of locksql: lockkit's client (dial, hello, call) with locksql's names and its SQL methods.
Package client is the secret-free side of locksql: lockkit's client (dial, hello, call) with locksql's names and its SQL methods.
config
Package config loads locksql profiles from the project and user config files, applies defaults, refuses anything that looks like a secret, and computes the security-relevant policy of a profile.
Package config loads locksql profiles from the project and user config files, applies defaults, refuses anything that looks like a secret, and computes the security-relevant policy of a profile.
console
Package console is the human side of locksql: it holds the credentials and the only database connection, enforces the approved policy, shows every query to the human for approval, masks the results and writes the audit trail.
Package console is the human side of locksql: it holds the credentials and the only database connection, enforces the approved policy, shows every query to the human for approval, masks the results and writes the audit trail.
engine
Package engine defines the database engine interface the console drives, and the engine-independent types it returns: catalog descriptions, result sets and normalised query plans.
Package engine defines the database engine interface the console drives, and the engine-independent types it returns: catalog descriptions, result sets and normalised query plans.
engine/mysql
Package mysql is the MariaDB and MySQL engine, on the go-mysql-org client (chosen because it reports each result column's origin schema, table and column).
Package mysql is the MariaDB and MySQL engine, on the go-mysql-org client (chosen because it reports each result column's origin schema, table and column).
engine/postgres
Package postgres is the PostgreSQL engine, on pgx v5.
Package postgres is the PostgreSQL engine, on pgx v5.
engine/sqlite
Package sqlite is the SQLite engine, on the pure-Go modernc.org/sqlite driver.
Package sqlite is the SQLite engine, on the pure-Go modernc.org/sqlite driver.
ipc
Package ipc is locksql's console protocol: lockkit's transport and methods (package lockkit/ipc, re-exported here under the same names) plus the SQL methods and their types.
Package ipc is locksql's console protocol: lockkit's transport and methods (package lockkit/ipc, re-exported here under the same names) plus the SQL methods and their types.
mcpserver
Package mcpserver exposes the locksql console to agents as MCP tools (spec §12).
Package mcpserver exposes the locksql console to agents as MCP tools (spec §12).
pii
Package pii decides which result cells must be masked: column rules kept in .locksql/pii.toml, rules proposed from the schema, value detectors (email, phone, IBAN, card, national ids) and the masking itself.
Package pii decides which result cells must be masked: column rules kept in .locksql/pii.toml, rules proposed from the schema, value detectors (email, phone, IBAN, card, national ids) and the masking itself.
product
Package product is locksql's identity on lockkit: its names, accounts, directories and keychain service.
Package product is locksql's identity on lockkit: its names, accounts, directories and keychain service.
proxycmd
Package proxycmd reaches a database through a command whose stdin and stdout carry the connection, as OpenSSH's ProxyCommand: docker exec, kubectl exec, or ssh to a host that relays to a socket.
Package proxycmd reaches a database through a command whose stdin and stdout carry the connection, as OpenSSH's ProxyCommand: docker exec, kubectl exec, or ssh to a host that relays to a socket.
render
Package render turns a (masked) result into the text an agent sees: TSV or JSON, within the profile's row, cell and output caps.
Package render turns a (masked) result into the text an agent sees: TSV or JSON, within the profile's row, cell and output caps.
sqlast
Package sqlast parses the read statements an agent may run (SELECT, WITH ...
Package sqlast parses the read statements an agent may run (SELECT, WITH ...
sqlaudit
Package sqlaudit is locksql's audit record on lockkit's audit log: one JSONL record per event, never secrets and never row data.
Package sqlaudit is locksql's audit record on lockkit's audit log: one JSONL record per event, never secrets and never row data.
sqlclass
Package sqlclass is locksql's first gate: a conservative, dialect-aware lexer and statement classifier.
Package sqlclass is locksql's first gate: a conservative, dialect-aware lexer and statement classifier.
sqlrefusal
Package sqlrefusal holds locksql's refusal codes, registered with lockkit's refusal package, and re-exports that package so call sites import one name.
Package sqlrefusal holds locksql's refusal codes, registered with lockkit's refusal package, and re-exports that package so call sites import one name.
stats
Package stats reads the console's audit log and counts the refusals by code and by the token or node that triggered them, so that grammar work starts with the constructs users hit most.
Package stats reads the console's audit log and counts the refusals by code and by the token or node that triggered them, so that grammar work starts with the constructs users hit most.
weight
Package weight turns a normalised engine plan into a verdict: OK, WARN or REFUSE.
Package weight turns a normalised engine plan into a verdict: OK, WARN or REFUSE.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL