Skip to content
Kutrion
Browse docs

api-integrations

Integrate Kutrion with AI agents and pipelines

One guide that picks the path by situation: an AI assistant on your laptop, a CI pipeline, or an unattended server. Each path gives the caller access through the broker instead of a copy of the credential.

Updated Nov 9, 2026

Every path on this page does the same thing differently: the caller, whether a coding assistant, a CI job or a cron script, receives access to a connection, not the credential behind it. Kutrion holds the credential, opens the session itself, and records each call against the identity that made it. Nothing on this page is the only way to hand an agent a credential. It is a way to hand it none, and to have an audit trail that says what it did.

Give automation its own identity

Do not run a pipeline, a script or a teammate’s tool on your own kt login. Copying that sign-in to another machine or job makes two holders of one sign-in, and the broker cannot tell them apart. Three things follow:

  • Anomaly scoring is pooled. Unusual-activity checks look at the account as a whole, so a job’s burst of reveals or deploys raises the score for you as well, and the checks that act on that score can then ask you to step up.

  • Step-up covers whoever holds the sign-in. A step-up proof belongs to the sign-in, not to the person. When you step up, anyone using the same sign-in is let through until the freshness window closes (TENANT_STEPUP_TTL_SEC, default 300 seconds).

  • A copied sign-in ends. Each refresh token is used once. If a token that has already been used is presented again, Kutrion revokes that whole sign-in family, answers refresh_reuse_detected and records a REFRESH_TOKEN_REUSE row in the audit log. Two machines sharing one stored sign-in will hit this sooner or later, and one of them is signed out.

    When Kutrion ends a sign-in this way, or refuses to renew one, it mails the account holder. The message leads with the device and time of the sign-in it ended, then asks you to review your devices, change your password and check the activity log.

Give each automation its own identity instead, so its sessions are attributed to it and its limits are its own:

  • CI (GitLab CI, GitHub Actions): a trust and kt ci-login --trust <id>, below. The job holds no Kutrion credential.
  • A workflow engine such as n8n: a client-secret workload that exchanges its secret for short-lived tokens, see Unattended workloads and n8n.
  • An assistant, or a server that cannot use the paths above: an agent principal from kt mcp install --client <id> or kt agent mint, below. A long-lived token is the weaker choice.

Both are scoped to the vaults and connections you name and can be revoked on their own without touching your sign-in.

If your own CLI or app is signed out without explanation, or you find a REFRESH_TOKEN_REUSE row in the audit log that you cannot account for, treat the sign-in as possibly copied:

  1. Open Active devices and revoke any device you do not recognize (a CLI registered by kt login shows as “Kutrion CLI on ”).
  2. Change your password.
  3. Read the activity log for the period before the sign-out: which vaults, connections and credentials were used, from where.
  4. Move whatever was sharing your sign-in onto its own identity as above, then sign in again with kt login.

Pick your path

Your situationRecommended pathSection
An AI assistant on your own machine (Claude Code, Cursor, Claude Desktop)kt mcp installAssistants
A CI pipeline (GitLab CI, GitHub Actions)A trust, kt ci-login, then kt runPipelines
A workflow engine or server that can fetch its own tokens (n8n)kt agent mint --workload client_secret; the secret buys 15-minute tokensUnattended workloads and n8n
An unattended server that cannot use the paths above (cron, a script)kt agent mint, then kt run; a long-lived token, so the weaker choiceServers
A team that shares one credential across CI, cron and n8nEach user or job gets its own identity; the credential stays in the shared vaultTeams

Every kt command below needs the CLI. Download it from the downloads page and sign in with kt login; KT_API_BASE (or --base) names your server, and there is no default. All templates here are not yet tested by us end to end. Each command and flag was checked against the shipped CLI, but treat the blocks as starting points and run them once against a non-production organization first.

An AI assistant on your machine

kt login
kt mcp install --client claude-code

--client is one of claude-code, claude-desktop, cursor or copilot. The command mints an agent principal for that client, keeps its credential in your operating system’s keychain, writes the client’s MCP config, and checks that the bridge starts. The config file holds the server address and the client name, never a credential. Restart the client when the command tells you to.

Cursor works the same way and writes ~/.cursor/mcp.json:

kt mcp install --client cursor

Limit what the assistant can reach

By default an agent can reach everything you can reach. Name the vaults and connections it should have instead; both flags repeat, and each takes an id or a name:

kt mcp install --client claude-code \
  --vault "Staging" \
  --connection staging-web-01 --connection staging-db-01

An unknown name, or a name that matches more than one item, is refused before anything is minted. Add --scopes vault.list,ssh.exec to choose the tools (ssh.exec is off by default and asks for an authenticator code before it mints), --days 7 to shorten the lifetime and --egress lan to declare that the assistant’s model runs on your own network. Check and revoke with kt mcp status and kt mcp uninstall --client claude-code. The full list of tools, the resource scope rules and the redaction behavior are in Connect an AI agent.

Point the agent at a dedicated, low-privilege account on the target host, so what it can do there is bounded by that account and not by yours. The reasoning is in Connect an AI agent.

A CI pipeline

The pipeline holds no Kutrion credential. GitLab CI and GitHub Actions each mint a short-lived signed token for the job; kt ci-login exchanges it for a short-lived agent, and kt run uses that agent. Background, the exchange rules and what a trust may reach are in CI pipelines without stored secrets.

1. Register a trust (once, an org owner or admin)

kt vaults        # find the vault id
kt trust add \
  --issuer https://gitlab.example.com \
  --audience kutrion \
  --subject 'project_path:group/repo:ref_type:branch:ref:main' \
  --vault <vault-id> \
  --connection <connection id> \
  --scopes vault.list,vault.use,ssh.exec \
  --exec-mode allowlist \
  --allow "<connection id>=<command>"

kt trust add needs a terminal. It asks for the code from your authenticator app and for a code it mails you, so the account needs an authenticator app (a passkey cannot be checked in a terminal) and the command cannot run from a script. It prints the trust id. Store it in a plain CI variable named KT_OIDC_TRUST_ID; it is not a secret. Also set KT_API_BASE to your server. For GitHub, use the issuer value that GitHub documents for Actions OIDC tokens. Default scopes are only vault.list,vault.use, so ask for ssh.exec explicitly, with --exec-mode and --connection, when the job runs commands, and for files.write only if it uploads files (that scope needs a fresh step-up).

2. GitLab CI

deploy:
  id_tokens:
    KT_ID_TOKEN:
      aud: kutrion
  script:
    - KT_AGENT_TOKEN=$(kt ci-login --trust $KT_OIDC_TRUST_ID) || exit 1
    - export KT_AGENT_TOKEN
    - kt run kutrion.yml --reporter junit --out report.xml
  artifacts:
    reports:
      junit: report.xml

3. GitHub Actions

permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      KT_API_BASE: ${{ vars.KT_API_BASE }}
      KT_OIDC_AUDIENCE: kutrion
    steps:
      - uses: actions/checkout@v4
      - run: |
          KT_AGENT_TOKEN=$(kt ci-login --trust ${{ vars.KT_OIDC_TRUST_ID }}) || exit 1
          export KT_AGENT_TOKEN
          kt run kutrion.yml --reporter junit --out report.xml

KT_OIDC_AUDIENCE must equal the audience on the trust. When it is unset the CLI asks GitHub for a legacy default audience, which a trust registered with --audience kutrion refuses. The runner also needs the kt binary installed; this page does not cover how you bake it into an image.

Assign the token on its own line

export KT_AGENT_TOKEN=$(kt ci-login ...) reports the exit status of export, not of kt ci-login, so a failed exchange would not fail the job and kt run would then run with whatever was around. Both templates above assign first, then export. In CI, kt run with no KT_AGENT_TOKEN is an error and never falls back to a stored login. Removing the trust makes the next exchange fail, and so the job.

The kt run job file, for a first-time reader

kt run reads a YAML file that lists steps. It lives in your repository next to the code and holds no credential, so a teammate can review it like any other change. Here is a small one:

name: restart and check
connections:
  api: prod-api-01
steps:
  - name: restart the service
    exec: { connection: api, command: "systemctl restart api" }
    expect: { exit_code: 0 }

  - name: service is active
    exec: { connection: api, command: "systemctl is-active api" }
    expect: { exit_code: 0, stdout_contains: active }

What each field means:

  • name (top level) is a label for the report. Optional.
  • connections maps a short alias to a connection, by its name or id as shown by kt conns. Steps use the alias. A step that uses an alias you did not declare is rejected.
  • steps run top to bottom. At least one is required.
  • A step’s own name is its label in the report. Optional.
  • The action is exactly one of exec (run a command), get (download a file), put (upload a file) or sync (mirror a directory between two connections). A step with none, or with two, is rejected.
  • exec takes connection and command. get takes connection, remote and local. put takes connection, local and remote. sync takes from and to, each with a connection and path, plus optional mirror: true (deletes extra files at the destination) and newer_only: true.
  • expect (on exec only) says what success looks like: exit_code, stdout_contains, stderr_contains, stdout_not_contains and stdout_matches (a regular expression). If you write no expect, the step still has to exit 0.
  • continue_on_error: true lets the run carry on after that step fails. Otherwise the run stops at the first failure and marks the rest skipped.

The job file cannot contain a credential. A key named password, passphrase, secret, token, private_key, api_key or value anywhere in the file is rejected, and so is a command that tries to interpolate a vault reference. There is no rotate step; rotate with kt rotation run or in the web app. Check a file without running it, and without any credential, using kt run kutrion.yml --dry-run. Reporters are console (default), junit and json; --out <file> writes the report to a file. The CLI reference is in the cli/README.md section “Job files in CI”.

On the pipeline path a get step returns the file as redacted UTF-8 text capped at 1 MB, so do not use it to move a binary, and a step your organization gates on human approval is refused rather than waited on.

An unattended server: cron and kt run

A server has no browser to sign in with and no OIDC provider. If it runs a workflow engine that can exchange a client secret for short-lived tokens, use Unattended workloads and n8n instead; the steps below hand the server a long-lived token, which is the weaker choice. Otherwise mint an agent for it from a machine where a person is signed in, scoped to what the job needs, and write its credential to a file only the service account can read:

kt agent mint \
  --name "nightly backup check" \
  --scopes vault.list,vault.use,ssh.exec \
  --scope-vault "Staging" --scope-conn staging-web-01 \
  --exec-mode allowlist \
  --allow "<connection id>=systemctl status backup.service" \
  --days 7 \
  --write-env /etc/kutrion/agent.env

ssh.exec needs --exec-mode: allowlist limits ssh_run to the exact commands you give with --allow <connection id>=<command> (the connection must also be named with --scope-conn) (repeat the flag for more, and add --ack with the same pair for a command rated block-level), while unrestricted is a full shell as the connection’s account. Without it the command refuses before minting anything. Minting an agent with ssh.exec asks for a passkey or authenticator code first; without a terminal to ask on, the command stops with step_up_required (exit 12), so run it from a machine where you can verify. If your organization asks for approval before an agent is minted, the command shows a code and waits for someone to approve the request through a link, then finishes the mint. --write-env writes KT_AGENT_TOKEN and KT_API_BASE to a file with mode 0600 and never prints the token. Without it the token is printed once. The command refuses to replace an existing file unless you pass --yes. The lifetime defaults to 30 days, but a principal that holds ssh.* or files.* scopes is capped at 7 days, so with ssh.exec the default drops to 7 and --days 30 is refused (--days 7 is the most you can ask for). Narrow the scopes to ones that do not reach hosts to go up to 90 days. There is no automatic renewal, so mint again before it ends (an expired agent makes kt run fail with a message to exchange a fresh one). Copy the file to the server, owned by the account that runs cron.

The wrapper script:

#!/bin/sh
set -eu
set -a
. /etc/kutrion/agent.env
set +a
exec kt run /opt/jobs/nightly.yml --reporter junit --out /var/log/kutrion/nightly.xml

The crontab entry:

15 2 * * *  /opt/jobs/nightly.sh

kt run exits 0 when every step passed and 1 otherwise, so cron’s mail or your monitor sees the failure. For a one-off command rather than a job file, kt exec <connection-id> <command> also uses KT_AGENT_TOKEN when it is set (it takes a connection id on this path, and --stdin is refused).

For a workflow engine that exchanges a client secret for short-lived tokens, including n8n, see Unattended workloads and n8n. That section is the reference; it is not repeated here.

Call it from a script

Two ways, both authenticated by KT_AGENT_TOKEN and KT_API_BASE in the environment.

Python, through the CLI

Run the job file and read the JSON report. The command’s exit status is non-zero when a step failed, and the report is on stdout:

import json
import subprocess
import sys

proc = subprocess.run(
    ["kt", "run", "kutrion.yml", "--reporter", "json"],
    capture_output=True,
    text=True,
)
report = json.loads(proc.stdout)
for step in report["steps"]:
    print(step["status"], step["name"])
sys.exit(0 if report["passed"] else 1)

For a single command, kt exec <connection-id> --json -- <command> prints {"result": {"code", "stdout", "stderr"}} when KT_AGENT_TOKEN is set, and exits with the remote command’s status.

Node, through the agent gateway

The gateway is POST {KT_API_BASE}/mcp, JSON-RPC over HTTP, with the agent token as a bearer credential. The mcp-method and mcp-name headers must mirror the body or the request is refused. This is the same call kt run makes; it lists the connections the agent can reach and runs one command:

const base = process.env.KT_API_BASE.replace(/\/+$/, "");
const token = process.env.KT_AGENT_TOKEN;
let id = 0;

async function tool(name, args) {
  const res = await fetch(`${base}/mcp`, {
    method: "POST",
    headers: {
      "content-type": "application/json",
      accept: "application/json, text/event-stream",
      authorization: `Bearer ${token}`,
      "mcp-protocol-version": "2026-07-28",
      "mcp-method": "tools/call",
      "mcp-name": name,
    },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: ++id,
      method: "tools/call",
      params: {
        name,
        arguments: args,
        _meta: {
          "io.modelcontextprotocol/protocolVersion": "2026-07-28",
          "io.modelcontextprotocol/clientInfo": { name: "my-script", version: "1" },
        },
      },
    }),
  });
  const reply = await res.json();
  if (reply.error) throw new Error(`${name}: ${reply.error.message}`);
  if (reply.result?.isError) throw new Error(reply.result.content?.[0]?.text ?? `${name} failed`);
  return reply.result.structuredContent;
}

const { connections } = await tool("ssh_list", {});
const out = await tool("ssh_run", { connection_id: connections[0].id, command: "uptime" });
console.log(out.exit_code, out.stdout);

Run it as an ES module (.mjs, Node 18 or newer). The token needs the ssh.exec scope. Output is redacted and capped at 256 KiB per stream, as described in Connect an AI agent.

Share credentials with your team

This walkthrough follows one credential from an admin to a team, and then into a GitLab CI job, a cron script and an n8n flow, without anyone using the admin’s login. The rule behind every step: a team never borrows an admin’s CLI session. Copying a kt login to a job or a colleague makes two holders of one sign-in (see Give automation its own identity). Each job or person gets an identity of its own, scoped to the vaults and connections it needs.

  1. An admin stores the credential. Create a vault and add the credential from a signed-in machine; --value-stdin reads the value from standard input instead of the command line.

    kt vault create "Infra"
    kt cred add <vaultId> --name "staging-web-01 login" --value-stdin
    
  2. The admin shares it with the infra team. Create the team and add its members:

    kt team create "Infra"
    kt team add <teamId> [email protected] --role EDITOR
    

    The CLI has no command that grants a team access to a vault. Do that in the web app, with the role described in Teams.

  3. A team member uses it in a GitLab CI job. The job holds no Kutrion credential. An org owner or admin registers a trust for the project, naming the vaults and connections it reaches, and the job runs kt ci-login and kt run. Follow A CI pipeline.

  4. A team member uses it in a cron script. The member mints an agent in their own name, scoped to the shared vault, and follows An unattended server. For a member (not an owner or admin) the mint waits for an owner or admin to decide it, and the member then finishes it with kt grant wait <requestId> --complete on their own computer or in the web app. The agent acts under its own principal and shows in the audit log under that name, not under the admin or the member’s sign-in.

  5. A team member uses it in an n8n flow. n8n exchanges a client secret for short-lived tokens. Mint that workload with kt agent mint --workload client_secret --scope-vault <id|name> and follow Unattended workloads and n8n.

Use without reveal: in each step the caller runs commands through the broker, which holds the credential and opens the session, so the caller never reads the value. Handing the value itself to an arbitrary program, as in an injection into a tool’s environment, is not available (see Not available yet).

Renewal and expiry. kt agent ls shows each agent as live, expiring, expired or revoked, with its expiry and last use, so check it for the ones your team depends on. Agents that reach hosts last at most 7 days. For an agent without ssh.exec, kt agent keepalive --on rotates its token before the 7-day end while it is in use on that machine; an agent with ssh.exec is refused keepalive because renewing it needs a passkey or authenticator code, so mint it again. If an admin revokes a member’s automation in bulk, that member’s automation stays frozen until an owner or admin clears it with kt member automation-freeze clear <userId> (it needs a passkey in the web app).

This walkthrough has not been run end to end by us.

Reach a LAN appliance through a credential action

A credential action is a fixed web request that Kutrion makes with a stored credential, so the caller never receives the credential. An organization owner or admin sets one up (POST /actions); a person or an agent listed on it runs it. An action can be marked as reaching a private network, for example a switch, a storage array or a controller with a web API on your own network, so the call is made from your self-hosted Kutrion server and recorded on the audit trail. This section describes what the server enforces; it is not an end-to-end tested template.

What a private-reach action is, and is not:

  • Read-only. A private-network action allows only GET and HEAD. Authoring one with another method is refused.
  • Three switches must all be on. The deployment lists the permitted networks in ACTION_PRIVATE_ALLOW_CIDRS (empty by default, so private reach is off; each entry must be a private range no wider than /24 for IPv4 or /64 for IPv6). The organization’s broker_private_targets must be allow. The organization owner must turn on action_private_reach with a step-up confirmation; an admin who is not the owner cannot. The org switches are checked again at every run, not only when the action is authored.
  • Some addresses are never reachable: loopback, link-local, cloud metadata addresses, the deployment’s own database and Redis hosts and its own interface addresses.
  • Pinned TLS. A private-reach action carries a pin: the SHA-256 of the appliance’s certificate public key (SPKI), as 64 hex characters. A run connects to the address Kutrion resolved and checks the presented key against the pin before any request byte is sent; a mismatch sends nothing and fails with tls_pin_mismatch (HTTP 424, as for any failure on the service’s side). A pinned connection does not validate the certificate chain, its expiry or its host name, so a self-signed appliance certificate works and an expired one carrying the pinned key is also accepted. A second, next pin can be staged so a certificate can be rotated: promote it, or clear it, with POST /actions/:id/pin. Trusting a different key otherwise means a new action (POST /actions/:id/repin), which supersedes and revokes the old one.
  • Trust on first use. POST /actions/preview shows the key the host presents, from the server, so you can compare it with the appliance itself. Kutrion does not verify that key for you. The preview sends no credential and writes no pin.
  • The credential must be injection-only. A person can run an action only when its credential is injection-only. Kutrion does not return the value, and the response is scrubbed of it. That scrub is accident prevention, not a guarantee: a value is kept from a runner only if no allowed path on the appliance echoes request headers back, so keep echo and debug endpoints out of the path rules.

Who runs it, and what each run needs:

  • A listed person: POST /actions/:id/run, as a member who is on the action’s user list and can read the credential’s vault. A private-reach run needs a fresh step-up confirmation from that person.
  • A listed agent: the action_run tool, for an agent holding the vault.inject scope. Every private-reach agent run waits for a person to approve that one run, whatever the organization’s other approval settings say.
  • Both are capped per action per day, and a burst limit applies per appliance address across all callers.
  • Refused for Private vault organizations, and for a person’s run while impersonating. A person’s run also needs the agent-access feature on the plan.

What is recorded: each run writes a credential-injection entry before the request is sent (with the action, the actor, whether a person or an agent, the host, the method, path, that the connection was pinned, the step-up method or approval used) and a completion entry afterwards (status, size, duration and whether the pin matched). A run is refused if the first entry cannot be written. Previewing, promoting and refusing are recorded too. The audit trail is tamper-evident through the checkpoint chain described in Architecture overview.

A response comes back with the credential scrubbed, secret patterns redacted and the organization’s data policy applied; it can be withheld, in which case the request was still sent.

Actions are set up through the REST API. This section has not yet been run against a real appliance, so test it against yours before relying on it.

Not available yet

These are not built, so there is no template for them. Progress is listed on the changelog.

  • Injecting a stored value into a tool’s environment without the caller seeing it. Today the broker can use a credential on your behalf; it cannot yet hand a value to an arbitrary program.
  • Per-command scope for ssh.exec. A principal with ssh.exec can run any command as the connection’s account; allowlist mode is refused. Use a low-privilege target account.
  • The Connector is not generally available.

Test status

Four of the eight blocks above have been run end to end against a staging organization (job 444154): cron with the kt run wrapper, the Python script, the Node script and the GitLab CI template. Each command shows in the audit trail under the agent’s own identity, and the GitLab CI trust exchange is recorded as well. The negative GitLab CI run, with the trust removed, fails the job and kt run never starts.

Still not executed by us: Claude Code and Cursor install, GitHub Actions (including its negative run with the trust removed, which must fail the job) and the n8n credential setup. Treat those four as a starting point until someone other than their author has run them against a non-production organization. The LAN-appliance section below has not been run through a template either.