Guide

Your AI agent ran all night: how to put a time limit on it

Nobody attacked it and nothing crashed. The agent was left running, kept going after the work was done, and the cloud bill arrived in the morning.

Short answer

Give every run a deadline and check it before each step, and also run each tool call with its own timeout, because a check inside the loop cannot stop a call that hangs. Hitting the deadline should end the run with an error, not just log a warning.

Teams building agents for real customers tell the same story. One agent left running cost about ₹25,000 on a cloud bill. Another, connected to a mailbox, kept acting on its own long after the job was finished. A time limit is the simplest guard against both.

Why agents keep running

  • Waiting on a signal that never comes. The agent polls for a result that was already delivered, or checks for a file that will not appear, and waits again.
  • No end to the job. The task is "watch this inbox" or "keep this running", and nothing says when to stop.
  • A hung call. One network request never returns, and the whole run sits behind it.
  • Nobody is watching. A run started on Friday evening is not looked at until Monday.

The fix: a deadline for every run

Give each run a maximum time and check it before every step. When the time is up, the run ends with an error you can alert on, instead of going quiet.

import time

class Deadline:
    def __init__(self, seconds):
        self.end = time.monotonic() + seconds

    def check(self):
        if time.monotonic() > self.end:
            raise TimeoutError("run exceeded its time limit")

deadline = Deadline(seconds=600)      # ten minutes for this run

while not done:
    deadline.check()                   # before every step
    result = call_tool(...)            # and give every network call its own timeout

We tested this on 20 November 2026 with a two-second deadline and half-second steps. The run stopped after 4 steps with a clear error.

The part people miss: a check inside the loop cannot stop a hung call

The deadline is only looked at between steps. If one call hangs for an hour, the check never runs. So the check needs a partner:

  • A timeout on every network call. Set it on the HTTP client and on the model call. A call that cannot hang cannot freeze the run.
  • A watchdog outside the process. A scheduler or supervisor that kills any job still running after its allowed time.
  • An alert when a limit fires. A run that stops silently at 3 a.m. is better than one that does not, but you still want to know.

Doing it with SteerPlane

SteerPlane has a runtime limit per run, max_runtime_sec. Install it with pip install steerplane:

from steerplane import SteerPlane
from steerplane.exceptions import SteerPlaneError

sp = SteerPlane(agent_id="nightly_agent")

try:
    with sp.run(max_cost_usd=5, max_steps=100, max_runtime_sec=600) as run:
        while not done:
            run.log_step("poll_inbox", tokens=10, cost=0.0001)
            ...
except SteerPlaneError as e:
    print(f"Stopped: {e}")          # a time limit ends the run with this kind of error

On version 1.1.3, a run with a three-second limit that kept stepping once a second was ended with a runtime error. If you set nothing, the limit defaults to 3,600 seconds, one hour.

One thing to know. The runtime is checked when a step is logged, the same as the deadline above. A single call that hangs and never returns will not be interrupted by it. Keep timeouts on your own network calls as well.

Time is only one limit. Pair it with a cost limit and a loop check, so a run is stopped by whichever it hits first. Setup is on the setup page.

A checklist before you leave an agent running

  • Every run has a maximum time, even runs that are meant to be long.
  • Every network call has its own timeout.
  • Something outside the process can kill a job that overruns.
  • Hitting the limit sends an alert, not just a log line.
  • You have left a test agent running on purpose and checked that it stopped.
Keep reading
Design partners

Shipping agents? Let's talk.

Our first 10 design partners get every paid feature free, plus direct help setting up.