Tegoby Attention SpanBlogBook a demo

Lock down Claude Code on Linux in seven steps

Claude Code runs as you, so it can read your SSH keys and .env files and reach any host. This guide runs it under Tego, which keeps it away from all three, in seven short steps and without root.

Tego runs an AI agent under rules you write, called a contract, and enforces them from outside the agent. The Claude Code and Codex docs page is the reference; this is the walk-through.

What the contract protects

The contract covers claude and everything it starts: its file tools, the shells its Bash tool opens, and any hook or MCP server.

  • Your secrets stay unread. SSH keys, cloud credentials (~/.aws, ~/.config/gcloud, ~/.kube/config), token stores such as ~/.config/gh and ~/.npmrc, browser profiles and .env files are on Tego's built-in deny_read list. Every contract has it unless it switches it off.
  • One host. Connections go only to api.anthropic.com:443 and the local name-service socket. DNS lookups still reach your resolver, because net.dns.mode defaults to system.
  • Two programs. Besides Claude Code and the hook Tego adds, only bash and git run. Anything else is refused and recorded.
  • Writes stay in the project, plus /dev/null, /dev/tty and one runtime folder. ~/.claude is never written: Claude Code keeps its state in .claude-state/ inside the project.
  • Only named variables pass. Claude Code gets the environment variables env.pass names, the ones the contract sets, and Tego's own.

The limits: anything Claude Code can read can go into a prompt to api.anthropic.com, so Tego is not data-loss prevention. Files off the deny list stay readable, and bash can do anything bash can do inside these rules. At Basic a .env inside the writable project can be renamed or hard-linked and read under the new name, so keep secrets outside the folders the agent writes. The security and limits page has the full list.

Before you start

You need Landlock ABI 2 or newer (Landlock is the kernel feature Tego uses without root; the ABI is its version): Linux 5.19 or later, or a backport such as RHEL 9's 5.14, plus cgroup v2 with a subtree delegated to your user. Any desktop login on Linux 6.1 or later, Ubuntu 24.04 included, works. Ubuntu 22.04's stock 5.15 kernel does not.

The kernel backs up network rules only from ABI 4 (Linux 6.7 or later, or RHEL 9's backport); below it, as on Debian 12's 6.1, Tego's supervisor alone decides each connection. tego doctor prints your ABI.

You also need claude on your PATH. Run everything in a plain terminal, as yourself. Over SSH, first start a shell in your user's cgroup:

Shell
systemd-run --user --scope bash

Step 1: Install Tego

Install the latest release with one command (Install Tego has the details):

Shell
curl -fsSL https://github.com/Attention-Span-AI/Tego/releases/latest/download/install.sh | sh

Or build from source with git, make and Go 1.27:

Shell
git clone --branch v0.1.3 https://github.com/Attention-Span-AI/Tego
cd Tego
make build
mkdir -p ~/.local/bin
install -m 0755 bin/tego bin/tego-control ~/.local/bin/
export PATH="$HOME/.local/bin:$PATH"

If a step fails, the Linux install guide has the requirements and fixes.

Step 2: Check the machine

Shell
tego doctor
tego test

tego doctor names your protection level: landlock (Basic) as a normal user. tego test tries four harmless moves on decoy files, such as reading a fake SSH key. 4 refused at tier landlock means you're ready.

Step 3: Copy the contract

Keep the contract outside the project, because Tego refuses a contract the agent could rewrite. This page was built with the latest release, v0.1.3; the installer may now fetch a newer release. If tego version shows a different release, use that release's tag for the contracts instead.

Shell
mkdir -p ~/contracts
curl -fsSL -o ~/contracts/claude-code-interactive.yaml \
  https://raw.githubusercontent.com/Attention-Span-AI/Tego/v0.1.3/examples/agents/claude-code-interactive.yaml

No user-id edit is needed. XDG_RUNTIME_DIR: "%R" asks Tego to create and remove a private runtime folder for Claude Code's session sockets. Keep your shell's XDG_RUNTIME_DIR short, normally /run/user/<uid>.

Run tego run as yourself, without sudo. If launch is refused with an XDG_RUNTIME_DIR message, check echo "$XDG_RUNTIME_DIR" in the shell that starts Tego: it must print a short absolute path such as your user's /run/user/<uid>. If it is unset, relative or too long, use a normal user login session that sets it, or export a short absolute directory only you can write, then retry.

The rules read:

claude-code-interactive.yaml
version: 0
name: claude-code-interactive
command: ["claude"]
record: full
capture: off
fs:
  write: ["./", "/dev/null", "/dev/tty"]
exec:
  allow: ["bash", "git"]
net:
  allow: ["unix:/var/run/nscd/socket", "tcp://api.anthropic.com:443"]
env:
  pass: ["PATH", "HOME", "LANG", "TERM", "COLORTERM", "CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY"]
  set:
    CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1"
    DISABLE_AUTOUPDATER: "1"
    CLAUDE_CONFIG_DIR: ".claude-state"
    CLAUDE_CODE_TMPDIR: ".claude-state/tmp"
    TMPDIR: ".claude-state/tmp"
    XDG_RUNTIME_DIR: "%R"
limits:
  pids: 512
  memory: 4GiB
  stall_after: 1h
ask:
  timeout: 5m

record: full lists the files Claude Code read, so a refused read of your SSH key shows up. capture: off leaves the bytes of model calls out of the record (with Tego's forwarder in the path, Claude Code exits on its first connectivity check); connections, writes, programs and refusals are still in it. stall_after: 1h ends a run idle for an hour, and typing counts as activity.

Step 4: Sign in outside Tego

Claude Code's own /login needs hosts this contract leaves out. Create a long-lived token once, outside Tego, and pass it in through the environment:

Shell
claude setup-token
read -rs CLAUDE_CODE_OAUTH_TOKEN && export CLAUDE_CODE_OAUTH_TOKEN

Paste the token at the silent prompt, so it stays out of your shell history, or set ANTHROPIC_API_KEY the same way. Both names are in env.pass, so only Claude Code gets them.

Step 5: Check the contract with --version

Go to your project and make the state folder the contract expects:

Shell
cd ~/code/my-project
mkdir -p .claude-state/tmp
tego compile ~/contracts/claude-code-interactive.yaml
tego run ~/contracts/claude-code-interactive.yaml -- claude --version

tego compile prints the rule table without running anything. The last line starts Claude Code under the contract with no login, the quickest check that the copy works.

If launch is refused for XDG_RUNTIME_DIR, follow the runtime-directory checks in Step 3 and retry as yourself, without sudo.

Step 6: Start a real session

Shell
tego run ~/contracts/claude-code-interactive.yaml

Claude Code opens as usual. When it tries something the contract rules out, the call fails with EACCES or EPERM, and a refused command commonly exits with status 126.

Tego also tells Claude why, through a hook it adds for this run only (your ~/.claude and the project's .claude/ stay untouched):

Output
Tego, this run's access control, refused 1 action:
- Tego refused write "/home/user/out.txt": this run may not write to that path (rule fs.write).

Safe mode and bare mode load no hooks, so Tego refuses such a run. The reason channel guide has the details.

Step 7: See what happened

When the session ends, read the run's receipt:

Shell
tego receipt --last

It lists files written, connections, programs, sensitive files read, and every refusal with its rule. Its first line names the run, such as r-40c94c9f-0dmkbl68johzb-hdcxpr; the last four or more characters are enough. Use the end of your own run id:

Shell
tego events hdcxpr
tego events hdcxpr --last
tego events hdcxpr --verify

The first prints the full record, --last the last refusal, gap or limit, and --verify checks nobody edited it. For a browser view, start the dashboard in a second terminal, as yourself, never with sudo:

Shell
tego serve --open

The dashboard guide walks through each page, and the tamper-evident record explains what the check proves.

When Tego refuses something you need

Name it in the contract: programs in exec.allow, such as "node" and "npm", and hosts in net.allow, such as "tcp://registry.npmjs.org:443". Run tego compile again to check.

tego learn proposes a contract from a finished run; read it first, because it describes whatever the run did. Write a Tego contract covers every key and preset.

How this compares with Claude Code's own sandbox

Claude Code's sandboxed Bash tool (as of 2 November 2026) is off until you run /sandbox. It covers "Bash, PowerShell, and Monitor commands and the processes they start"; file tools, MCP servers and hooks run outside it. By default it allows reads across most of the machine, credential files included, and if it can't start, commands run without it unless sandbox.failIfUnavailable is set.

Tego's contract covers the whole process tree, with the deny list on by default. The two don't stack: Claude Code's Linux sandbox uses bubblewrap, which can't start inside a Tego run today, and we haven't tested what Claude Code then does. Claude Code permissions vs sandbox compares the two built-in guards.

Is --dangerously-skip-permissions safe under Tego?

No. Anthropic's advice is to "Always run --dangerously-skip-permissions sessions inside a container, a VM, or the sandbox runtime" (Choose a sandbox environment). Tego is none of those: it doesn't hide the machine, and an allowed host is still a way out. Tego can run inside such a VM; comparing ways to sandbox AI agents sets out what each option isolates.

Next, read why the rules live outside the agent in a prompt is not a security boundary, or start from Get started with Tego.

Sources (6 links)

Anthropic sources checked on 2 November 2026.