0
Phase 18

Terminal Agent

~3 min read

Concept & How It Works

    Why Does It Exist?

    Much of engineering still happens in the terminal. Agents that can run commands accelerate exploration and automation, but require strict sandboxing to prevent destructive mistakes.

    Real-World Analogy

    An intern with a supervised shell — they can run commands you approve, in a disposable VM, with command blocklists for `rm -rf /`.
    Loading diagram...

    Visual Workflows

    What is Terminal Agent?

    Loading diagram...

    Example

    Scenario

    User asks 'why is port 3000 in use?' The agent runs `lsof -i :3000`, identifies a stale node process, asks permission, then kills it and verifies the port is free.

    Solution

    In Coding Agents, apply Terminal Agent to this scenario: User asks 'why is port 3000 in use?' The agent runs `lsof -i :3000`, identifies a stale node process, asks permission, then kills it and verifies the port is free. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to Terminal Agent (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where Terminal Agent happens in the code.

    Terminal Agent
    1async function runTerminalCommand(cmd, opts) {  # key line for Terminal Agent2  if (DENYLIST.some(d => cmd.includes(d))) throw new SecurityError("command blocked");3  if (REQUIRES_APPROVAL.some(p => cmd.startsWith(p)) && !opts.approved) {4    return { status: "pending_approval", command: cmd };  # return the result5  }6  const proc = spawn("bash", ["-c", cmd], { cwd: opts.cwd, timeout: 60_000 });7  const { stdout, stderr, exitCode } = await collectOutput(proc);8  audit.log({ event: "terminal.exec", cmd, exitCode });  # key line for Terminal Agent9  return { stdout: truncate(stdout, 50_000), stderr, exitCode };  # return the result10}

    Commands to Remember

    Commands to Remember

    • pip install openai # code generation and review
    • gh pr create # open a pull request from agent output

    Common Mistakes

    • Treating Terminal Agent as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for terminal agent

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • Terminal Agent
    • Sandbox
    • Command Allowlist
    • Ephemeral Container