Foundational Compute

Run an AI engineer

Give an AI agent its own Linux computer that stays ready between tasks. You bring the model key.

Templateclaude (2 vCPU, 2 GiB, $0.048 per hour)
Between tasksPaused: memory, files and programs kept, free for up to 72 hours
Cost4 hours of work a day costs about $5.84 a month.
Cleanupfdtn kill @engineer deletes the sandbox and its files.

What you need

  • An FDTN API key. Run fdtn auth or set FDTN_API_KEY. Quickstart
  • A model key. Set ANTHROPIC_API_KEY on your computer. Any agent works the same way: build its CLI into a template and pass its key, for example OPENAI_API_KEY. Templates
  • A GitHub token (for a private repo). Set GH_TOKEN to a token with access to one repo.

1Start the engineer's computer

$ fdtn create claude -d --name engineer --timeout 3600 --lifecycle.ontimeout pause

After 1 hour the sandbox pauses. It is not killed.

The claude template runs only on machines we own (trusted placement). Put keys only in trusted sandboxes. Security

2Give it a repo

$ fdtn exec @engineer -- git config --global credential.helper \
    '!f() { echo username=x-access-token; echo "password=$GH_TOKEN"; }; f'
$ fdtn exec -e GH_TOKEN="$GH_TOKEN" @engineer -- git clone https://github.com/your-org/your-repo repo

Git reads GH_TOKEN only when it runs. The token is not in the clone URL, .git/config or metadata. For a public repo, omit the token.

3Give it a task

$ fdtn exec -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" @engineer -- \
    sh -c 'cd repo && claude -p "Fix the failing test. Run the tests."'
$ fdtn exec @engineer -- sh -c 'cd repo && git diff'

Give the model key with each task. It is then not in the sandbox environment between tasks. fdtn exec returns the exit code of claude.

4Keep it between tasks

$ fdtn pause @engineer                  # memory, files and programs kept; free for 72 hours
$ fdtn resume @engineer                 # next task
$ fdtn sandbox timeout @engineer 3600   # 1 hour from now, then it pauses again

A resume gives 5 minutes. Set the time left before a long task. Pause and resume

5Talk to it

$ fdtn connect -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" @engineer
user@fdtn:~$ cd repo && claude

fdtn connect resumes a paused sandbox. When you leave, the sandbox runs until its time ends, then pauses.

6Stop it

$ fdtn kill @engineer

A kill deletes memory and files. Push the work or copy it out first.

From Python

Start the engineer once. Then give it a task on any day within 72 hours of the last pause.

engineer.py
import os, shlex, sys
from fdtn import Sandbox, CommandExitException

REPO = "https://github.com/tartley/colorama"
KEYS = {"ANTHROPIC_API_KEY": os.environ["ANTHROPIC_API_KEY"]}

def start():
    sbx = Sandbox.create(
        "claude",
        timeout=3600,                        # 1 hour, then pause
        request_timeout=300,
        lifecycle={"on_timeout": "pause"},   # pause, not kill
        metadata={"role": "engineer"},
    )
    sbx.commands.run(f"git clone --depth 1 {REPO} repo", timeout=120)
    sbx.pause()                              # free while paused, up to 72 hours
    return sbx.sandbox_id

def work(sandbox_id, task):
    sbx = Sandbox.connect(sandbox_id, timeout=3600)   # resume for 1 hour
    try:
        r = sbx.commands.run(f"claude -p {shlex.quote(task)}",
                             cwd="/home/user/repo", envs=KEYS, timeout=1800)
        print(r.stdout)
    except CommandExitException as e:
        print(f"exit {e.exit_code}:", (e.stdout + e.stderr).strip())
    print(sbx.commands.run("git status --short", cwd="/home/user/repo").stdout)
    sbx.pause()

if sys.argv[1] == "start":
    print(start())                           # keep this ID
else:
    work(sys.argv[1], sys.argv[2])           # python engineer.py <id> "task"
$ python engineer.py start
$ python engineer.py <id> "Add a test for colorama.__version__."

Security

  • Give keys only as environment variables: -e or envs. Never write a key into a sandbox command, a file or metadata.
  • Use trusted placement for every sandbox that holds a key. The claude template always does.
  • Give the engineer its own model key with a spending limit, and rotate it.

Next