ksproxy
Let AI agents run allowlisted ssh, kubectl, local, database, queue and HTTP API calls without your credentials.
What it does
ksproxy lets an AI agent run commands on ssh servers and Kubernetes clusters without ever holding a credential, run a short list of commands in a folder on your own machine, and use databases, queues and HTTP APIs (PostgreSQL, MySQL, MongoDB, Redis, Elasticsearch, RabbitMQ, Kafka and any HTTP API). You run one command in a terminal, pick the targets, and leave it running; the agent reaches those targets only through a built-in MCP server. Every call is checked against a per-target allowlist that refuses everything by default, every call is logged, and Ctrl-C closes all access.
What it is for, and what it is not
ksproxy is made for one job: developing and debugging with an AI agent, safely. The agent can look at logs, inspect a cluster, read a few rows or check a queue, while you keep the credentials, decide what is allowed, and can read afterwards what was done. Safety comes first: when ksproxy is not sure, it refuses.
It is not a general proxy, a tunnel, or a tool to move data. These limits follow from that purpose:
| Limit |
What it means |
| One call, one answer |
Every call is one command, request or statement that ends. There is no interactive shell, no open connection between calls, and nothing is streamed. |
| Output is cut at 256 KiB |
Each of the two output streams is cut at 256 KiB and the answer says so. A large file or a large result does not pass through; the agent must ask for a piece (head, tail, grep, limit, a filter). maxOutputKiB in the inventory raises the limit to at most 4 MiB for one target. A large answer fills the agent's context, so raise it only where it is needed. |
| A call has a time limit |
60 seconds by default, 600 at most. The limit stops the program on your machine; a command already running on an ssh server, or a statement on a MySQL server, may go on there until it ends. |
| Small results from databases |
MongoDB returns at most 100 documents per call and never leaves a cursor open, so a larger result is read page by page with a filter. MySQL returns at most 1,000 rows. Change streams, getMore and other calls that wait or continue are refused. |
| No file transfer |
Nothing copies a file to or from a target. |
| Rules match words, not meaning |
A rule decides by the words of a call. It does not understand what a command does, so the rights of the account a target uses are the real boundary. Use a read-only account wherever you can. |
| Not a wall against your own user |
A process that runs as your user and can inspect processes or read your files can reach what ksproxy start holds. Run the agent without a shell of your user, in a sandbox, or as another user. Projects do not change this. |
| macOS and Linux only |
Node.js 24 or newer; the ksproxy program needs an env that knows -S (macOS, or GNU coreutils 8.30 or newer). |
The details are in Security model and limits and, for databases, queues and HTTP APIs, in docs/SERVICES.md.
Install
Requires Node.js 24 or later and ssh. kubectl is needed only for Kubernetes targets, and psql, mysql or mariadb, mongosh and the Kafka client programs only for the kinds that use them. There are no npm dependencies. macOS and Linux only. The ksproxy command starts Node through env -S with --disable-sigusr1, so the system's env must support -S, as the env of macOS and of GNU coreutils 8.30 or later do.
npm install -g @ksproxy/cli
That puts ksproxy on your PATH. To run from a checkout instead:
git clone https://github.com/ksproxy/cli.git ksproxy
cd ksproxy
npm link
Homepage: https://ksproxy.github.io/cli/ · Source: https://github.com/ksproxy/cli · Releases: CHANGELOG.md · Reporting a vulnerability: SECURITY.md
Quick start
-
ksproxy init writes a sample inventory to ~/.config/ksproxy/inventory.json (mode 0600) and prints its path. It never overwrites an existing file.
-
Edit the inventory: your own targets, and an allow list for each. A target with no allow refuses everything.
-
ksproxy start asks which kinds (ssh, kubernetes, local and the service kinds) and which targets to open, opens them (ssh may ask for your password or key passphrase in this terminal), prints a summary, and stays in the foreground printing one line per agent call and per event (see "The log" below). Non-interactive: --ssh a,b, --kube x,y, --local p,q, the flags of the service kinds (see "Databases, queues and HTTP APIs"), --all. Run ksproxy start with the environment variables that your service targets name. Without a terminal and without one of these flags, start exits with an error. Opening a local target only checks that its folder exists and may be used (see "Local targets"); closing it does nothing. -v / --verbose adds the matched rule and the output sizes to each allowed call.
-
Add the printed MCP config to your agent once. For Claude Code the summary prints the exact line:
claude mcp add ksproxy -- <node> --disable-sigusr1 <path to bin/ksproxy.js> mcp
The config is the same on every run, so you do this once.
-
Press Ctrl-C when you are done. Every ssh connection and tunnel is closed, every proxy is stopped, session.json and the socket folder are removed, and the audit log in logs/ is kept. The other session files (ssh_config, kubeconfig, AGENT.md, mcp.json and the proxy logs) stay until the next start.
Other commands: ksproxy status [--project NAME] (every live session and each target's state, then the time of the last call and the number of calls this session; exit 0 only when everything is up), ksproxy log [-n N] [--denied] [--json] [--from ADDRESS] [--project NAME] (the history, see "The log"), ksproxy token and ksproxy token revoke (the network token, see "Network access"), ksproxy check [--project NAME] <flag of the kind> <name> <command...>, for example ksproxy check ssh web1 uptime (see below), ksproxy doctor (takes the arguments of start and checks every target without opening a session, see "Checking your targets with doctor"), ksproxy mcp [--project NAME] (the MCP server; your agent starts it, you do not), ksproxy --help, ksproxy --version. ksproxy init and ksproxy start take --project NAME too. ksproxy start also takes --project a,b (several projects, see "Projects") and --listen HOST:PORT, --new-token, --tls-cert FILE and --tls-key FILE (see "Network access").
Only one session runs at a time for each project, and for the default (no project). start refuses while a live session of the same project exists and cleans up a stale one. See "Projects" below.
Checking your targets with doctor
ksproxy doctor tells you, target by target, whether your inventory still works: the credential is there, the target can be reached and opened, and one harmless read succeeds. It changes nothing on any target.
It takes exactly the arguments of ksproxy start: --project (one name or a list), --all, the kind flags, -v, --listen, --tls-cert and --tls-key. --new-token is accepted and changes nothing. Target names may also be given as plain words (ksproxy doctor web1 shop-db). With no selection, doctor checks every target of the selected projects and never shows the picker. It has no flag of its own.
When ksproxy start fails, run the same line again with doctor in place of start. start stops at the first problem; doctor goes on and shows all of them in one run. It reports:
- the pre-checks of
start, in the order of start: the inventory of each project loads; no session of the project runs; the --listen values are valid; the TLS files can be read and belong together; no other program listens on the address; the token file can be read. A failed pre-check is printed as FAIL with the message of start. With --listen, doctor also opens each address for a moment and closes it again, without making a token.
- each target: doctor reads its credential from the environment, applies the inventory checks and prints the warnings that
start prints, opens the target the way a session does, runs one fixed, read-only check of its kind, and closes it. Targets are checked one after another. The check is fixed by ksproxy; it is never taken from your allow rules, and it is never sent to the model reviewer.
| Kind |
The check |
ssh |
The connection opens. Nothing is run on the server. |
kubernetes |
GET /version through the opened proxy. |
local |
The folder checks. |
http |
The host answers on its port (TLS for https). No request is sent. |
command |
The program is found. Nothing is run. |
elasticsearch |
GET /_cluster/health |
rabbitmq |
GET /api/whoami |
redis |
PING |
postgres, mysql |
select 1 |
mongodb |
The ping command. |
kafka |
List the topics. |
A kind with no check of its own is OK once it has opened. Each target has its open time limit and then 30 seconds for the check, so a dead host does not hang the run. Ctrl-C stops the run, closes what is open and exits 1.
$ ksproxy doctor
10:00:01 -- inventory OK loaded /home/someone/.config/ksproxy/inventory.json
10:00:01 -- session OK no session is running
10:00:01 ssh web1 OK connected
10:00:02 kube lab OK server v1.31.2
10:00:02 loc infra OK folder checks passed
10:00:03 pg shop-db OK select 1 answered
10:00:03 rds cache OK PONG
10:00:04 es es-logs FAIL HTTP 401 from GET /_cluster/health: authentication failed
5 of 6 targets OK
Each line has the format of the log: OK or FAIL and a short detail, cleaned, with every secret value hidden. The lines that start would print while it opens a target (WARN, SKIPPED) are printed too. With several projects each line starts with [NAME], as in start. The last line is N of M targets OK.
Exit code: 0 when every checked target is OK, 1 otherwise, 2 for a usage error.
- A project with a running session is reported as
FAIL (a session of project NAME is running, with its process number) and its targets are not opened, because a session holds fixed ports and the socket folder. Other projects of the same run are checked. To look at a running session, use ksproxy status.
- It writes nothing a session writes. It uses a temporary socket folder of its own and removes it at the end. If doctor is killed before it can remove the folder, the next
ksproxy doctor or ksproxy start stops the cluster proxies and ssh connections left in it and removes it; a folder left empty by a doctor killed while it was making it is removed once it is five minutes old. It never writes session.json, the call socket or the agent files, so no agent can reach a target through it, and it writes nothing to the audit log.
- It does contact every checked target with your credentials, with the one read of its kind. It does not run your
allow rules (use ksproxy check for that) and it repairs nothing.
Projects
A project is a set of targets for one agent, kept in its own inventory file. Use projects when two agents work in two repositories at the same time and each should be offered only its own targets. Nothing changes for you if you never pass --project.
-
ksproxy init --project shop writes a sample to ~/.config/ksproxy/projects/shop.json (folder mode 0700, file mode 0600). The file has the same format as inventory.json, with its own reviewers. It never overwrites a file.
-
ksproxy start --project shop --all opens the targets of that file only. The picker, --all and the kind flags choose among them. The session files and the log are in ~/.ksproxy/p/shop/. If the file is missing, start says inventory not found: <path>; run: ksproxy init --project shop.
-
The MCP config and the Claude Code line that start prints end with mcp --project shop. Add them to the MCP configuration of the repository of that agent:
claude mcp add ksproxy -- <node> --disable-sigusr1 <path to bin/ksproxy.js> mcp --project shop
ksproxy mcp --project shop reads only the session of shop. With no live session every tool answers No active session. Ask the user to run and the command ksproxy start --project shop.
ksproxy start --project shop,ops --all runs several projects in one process and one terminal. --project takes a comma-separated list only for start. Each project runs as a separate start would: its own inventory file, state folder, session, log and health checks. Before anything opens, start checks every project, and if one check fails, nothing opens and start exits 1 with the message of the first failure. With several projects, every output line starts with [NAME], such as [shop]. The kind flags, such as --ssh a,b, need a single project. Without --all, the picker runs once per project in a terminal; outside a terminal, several projects need --all. When one project stops, all of them stop, and start exits 1.