Tegoby Attention SpanBlogBook a demo

Run your agent under Tego

Updated

Copy a ready contract, make any changes its header asks for, and your agent runs with Tego deciding what it may write, run and reach.

On this page

A contract is the file of rules Tego holds your agent to (a YAML file such as agent.yaml). The Tego repository has ready ones for Claude Code and Codex. 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.

Get the contracts:

Terminal
git clone --branch v0.1.3 https://github.com/Attention-Span-AI/Tego

Git warns that the tag is not a commit! and prints a note about a detached HEAD. Both are normal for a tag.

You need Tego installed (Quickstart) with tego test passing (it shows Tego refusing four harmless actions), and the agent on your PATH on the same Linux system. On a Mac or Windows that is inside the Linux VM from Install. Keep contracts outside the project folder: Tego refuses a contract the agent could rewrite.

Run Claude Code

claude-code-interactive.yaml is for a person at the full-screen interface. Its main rules:

YAML
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_CONFIG_DIR: ".claude-state"
    CLAUDE_CODE_TMPDIR: ".claude-state/tmp"
    XDG_RUNTIME_DIR: "%R"
limits:
  stall_after: 1h

Claude Code writes in the project and a private runtime folder, plus /dev/null and /dev/tty. It reaches only Anthropic's API and the local name-service socket. XDG_RUNTIME_DIR: "%R" asks Tego to create and remove the private folder for 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.

Of your programs it runs bash and git; add the tools your task needs. Its state stays in ./.claude-state/, so your ~/.claude is never written. A run with no activity for an hour ends; typing counts. (The file has a few more lines, such as memory and process limits.)

  1. Copy it. No user-id edit is needed:

    Shell
    mkdir -p ~/contracts
    cp Tego/examples/agents/claude-code-interactive.yaml ~/contracts/
  2. Sign in once, outside Tego. Claude Code's own /login needs hosts the contract leaves out, so the token comes through your shell instead:

    Shell
    claude setup-token
    export CLAUDE_CODE_OAUTH_TOKEN=<the token it printed>

    With an API key, export ANTHROPIC_API_KEY=<your key>. Tego hands it to Claude Code and to nothing else.

  3. From your project folder, check that Claude Code starts under the rules:

    Shell
    cd ~/my-project
    mkdir -p .claude-state/tmp
    tego run ~/contracts/claude-code-interactive.yaml -- claude --version
  4. Start a session:

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

For one metered task (claude -p) with every model call recorded and a cost limit, use claude-code.yaml; its header says how to set the price table it needs. To lock it down further, add the strict setup.

When Claude Code is refused

A refused action fails like any denied file or program, and Claude is told why. Tego adds a note beside the tool result:

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).

Claude sees the reason next to the tool result, so it can carry on with the task another way. Tego installs this hook for the run only, through Claude Code's --settings; your ~/.claude and the project's .claude/ are not touched. Every refusal is also in the run's record (tego events <run> --last prints the latest) and on the dashboard. Any other agent or script in the run can read the latest refusals from the file $TEGO_REASON names.

Claude Code's --safe-mode and --bare load no hooks, so Tego refuses those runs. If the agent needs something the contract refuses, change the contract and start a new run: the rules don't loosen while it runs.

Run Codex

Codex works the same way, with two differences. Its own sandbox can't start inside a Tego run, so the contracts turn it off and Tego's rules take its place. And its contracts have more lines to change: every /home/USER/ and the folder of Codex's helper binary.

With a ChatGPT plan, use codex-chatgpt.yaml:

Shell
mkdir -p ~/.local/share/tego/codex-chatgpt
codex login
cp ~/.codex/auth.json ~/.local/share/tego/codex-chatgpt/auth.json
chmod 600 ~/.local/share/tego/codex-chatgpt/auth.json
printf 'sandbox_mode = "danger-full-access"\napproval_policy = "never"\ncheck_for_update_on_startup = false\n' \
  > ~/.local/share/tego/codex-chatgpt/config.toml

cp Tego/examples/agents/codex-chatgpt.yaml ~/contracts/
sed -i "s#/home/USER/#$HOME/#g" ~/contracts/codex-chatgpt.yaml
sed -i "s#/CHANGE/#$(dirname "$(readlink -f "$(command -v codex)")")/#" ~/contracts/codex-chatgpt.yaml

Its deny_read line names four files in your ~/.codex; remove any you don't have, or the contract won't compile. Then, from your project folder:

Shell
mkdir -p work/tmp held
tego run ~/contracts/codex-chatgpt.yaml -- codex --version
tego run ~/contracts/codex-chatgpt.yaml

Codex may write only in ./work/. A write under ./held/ waits until you approve it with tego approve or on the dashboard.

With an OpenAI API key, use codex.yaml. It sends every model call through Tego, so each request and response is recorded and counted. It needs a Codex config.toml built from the repository's test config, and you type the key at Codex's login screen; the file's header walks through both. Its rules are tested, but it hasn't yet been run with a real key. While it runs, don't run a second agent of yours under Tego: that agent could read the key you typed.

Run any other agent

Tego runs any agent that is a Linux process: a Python script, an agent on the Claude Agent SDK, an MCP server, a CI job. Only one thing changes: you write the contract for your command instead of copying one.

Shell
tego init --preset no-secrets,no-prod,repo-only-writes --write ./out --command "python3 worker.py"
tego compile agent.yaml
tego run agent.yaml

The presets keep secret files and variables from the agent, allow no network host but its model and the ones you list, and allow writes only in the folders you name. If your agent needs an API key, add its name under env: pass: in agent.yaml. Write rules explains each line.

Not sure what your agent needs? Record one run with tego watch -- <command>, which refuses nothing, then let tego learn <run> propose a contract that allows what that run did. Read what it proposes before you use it. The repository also has custom-agent.yaml for an agent left to run unattended, with every limit set, and contracts for the Claude Agent SDK and the Anthropic Python SDK.

Need a ready contract for another kind of agent, such as an MCP server, a Python worker, a CI job or an always-on assistant? Open an issue with what your agent runs and what it touches.

Use Claude Code's permission prompts alongside Tego

Keep them if you like them. Claude Code's prompts live inside the agent, so a setting or a flag such as --dangerously-skip-permissions switches them off. Tego's rules and its approvals live outside the agent, and they hold whatever the agent is told to skip. Tego is not a VM: the agent runs on your machine and can read whatever the contract doesn't deny. Claude Code's own Bash sandbox can't start inside a Tego run. What a contract can't stop is on Security and limits. How the two fit together is in What Claude Code's sandbox really stops.