Skip to content

Lesson 7 of 8 · 5 min read

Terminal Agents: One Shell, Many Commands

A terminal tool gives a coding agent a shell it can type into across many turns. Running each command in a fresh process loses state the agent relies on (the working directory, an activated environment, exported variables), so the useful design is one persistent shell process with a protocol for finding where each command's output ends: an end marker printed after every command carries the exit code. Around that sit the controls. Every command string is split into its component commands and each is checked against policy before any runs, because one line can hide several commands. The environment is non-interactive so that pagers, editors and prompts cannot block. Output is stripped of terminal control codes and capped with a note of what was cut. A command that exceeds its timeout kills the shell, and the restart tells the model which state (directory, variables, background jobs) was lost rather than silently starting fresh. The sandbox remains the boundary; the shell tool is a convenience inside it.

Premium lessonReviewed By the AIAgentInterviews editorial team
Get full Premium access · $25

All 19 topics with every worked answer, all lessons and courses, the full practice bank, and anything new that appears during your access.

6 months · One payment · No auto-renewal

Practise it as an interviewer asks it

Related lessons