← All projects

Design, implementation and evaluation

Autonomous Docker Terminal Agent

A ReAct agent that drives a persistent PTY inside a hardened Docker sandbox, answers its own interactive prompts, and cannot finish until the tests pass.

AIBackend
docker · 9/10 tasks
Tasks solved on a fixed 10-task suite
9/10
Average steps per task
7.9
Average model cost per task
$0.006
Walkthrough

The problem

Most terminal agents pipe strings into a normal child process. That works until a script asks a question: read -p, a [y/N] prompt, a password. The process blocks, the agent waits forever, and the run dies with no useful signal. The second problem is worse than the hang: an LLM with shell access will eventually try to write outside its workspace, and a naive path check does not stop a symlink.

So the real problem was not "let a model run bash". It was building an execution environment where a model can run bash, hang, fail and misbehave without taking the host with it — and still be provably finished when it claims to be.

Approach

  • Persistent PTY, not spawned commands. A node-pty shell keeps cd, environment variables and history across turns. Large generated scripts are written to host-side files and sourced into the session instead of being pasted through the 4 KB TTY buffer.
  • A sentinel-based exit code. Every command is followed by a randomised __DONE_UUID__:$? marker, so the agent reads the real exit code of the command and not of its wrapper.
  • Hang detection. A background heartbeat notices an idle prompt and hands the model a send_input tool, so it can type an answer and press enter without standard IO piping. interrupt sends Ctrl-C when a loop will not end.
  • A symlink-safe path jail. Iterative lstat and realpath resolution runs on every file operation, so dangling symlinks and ../.. traversal resolve to a rejection rather than to /etc.
  • Context that survives noise. Up to 220k characters are buffered and aggressively truncated before the API call; old tool outputs are replaced with lightweight stubs so a noisy install cannot erase the objective.
  • A finish gate. The finish tool stays locked until a test command returns exit code 0. The agent cannot declare success on vibes.
  • Seven tools and a 25-step cap inside ephemeral node:20-bookworm-slim containers started with --cap-drop=ALL and restricted PIDs.
  1. 01Objective
  2. 02ReAct loop: reason, then act
  3. 03PTY shell inside a Docker sandbox
  4. 04Sentinel exit codes and hang detection
  5. 05Context compaction with stubbed history
  6. 06finish, gated on a passing test run

Results

Evaluated on a fixed suite of 10 tasks that includes interactive prompts, syntax errors, infinite loops and a deliberate symlink escape attempt, using gpt-oss-120b via Groq.

MetricValueNote
Tasks solved9/1090% pass rate on the suite
Average steps7.9Per task
Average cost$0.006Per task
Tools exposed7send_input, interrupt, finish among them
Step cap25Hard limit per task
Sandbox--cap-drop=ALLPlus PID, CPU and memory limits

Three edge cases were handled by the general mechanism rather than by special-casing:

Case in the suiteWhat breaks a naive agentWhat handles it here
A hanging read -p promptThe process blocks and the run dies on timeoutsend_input types the answer and presses enter
An infinite while true loopThe agent waits until the step cap with nothing to showinterrupt sends Ctrl-C, then the script is rewritten
A write to /etc/hacked.txtA sibling prefix or symlink escapes the workspacerealpath jail rejects it and the agent recovers to /workspace

The one failure is reported as a failure. A 9/10 with the failing case documented is more useful than a claimed 10/10 that quietly dropped the hard task.

What went wrong

The PTY sentinel bug. Exit codes were occasionally read from the wrong command because the sentinel matched the shell's own echoed command line, so a failing run could look clean. The fix was a no-echo shell plus a randomised, digit-anchored sentinel, with a Vitest regression test that reproduces the interleaving.

Three path-jail escapes. A sibling-prefix path, a write through a symlinked directory, and a dangling symlink could each resolve outside /workspace. Each was closed with realpath-based resolution and a regression test, so the next refactor cannot quietly reopen them.

Limits. Docker Desktop is required, the suite is only ten tasks, and the budget is one model on one provider. The cost figure is model spend, not the machine time the sandbox consumes.