r3con (distributed on PyPI as r3context)
Copyright (c) 2026 Michael Theologitis

This product includes software developed at Hugging Face Inc.

--------------------------------------------------------------------------------
src/r3con/runtime/python_executor.py
--------------------------------------------------------------------------------

This file is a modified copy of `local_python_executor.py` from smolagents v1.25.0,
copyright 2024 The HuggingFace Inc. team, licensed under the Apache License,
Version 2.0. A copy of that licence is distributed with this package as
LICENSE-APACHE-2.0; the file itself retains the original copyright and licence
notice, and its header enumerates every modification made.

    Upstream: https://github.com/huggingface/smolagents/blob/v1.25.0/src/smolagents/local_python_executor.py

Modifications (also listed in the file header):
  - Removed the smolagents `Tool` import and the `send_tools` method; static tools
    are wired directly in `__init__`.
  - Inlined `BASE_BUILTIN_MODULES` and `truncate_content` from `smolagents.utils`
    so the file has no smolagents imports.
  - Upgraded `BreakException` / `ContinueException` / `ReturnException` from
    `Exception` to `BaseException`, so agent-emitted `try/except` cannot swallow
    control flow (upstream already does this for `FinalAnswerException`).
  - Repackaged from `smolagents` into `r3con.runtime`.
  - Sorted `authorized_imports` in `LocalPythonExecutor.__init__` instead of
    listing a set, so the refused-import message lists the modules in the same
    order in every process (set order varies with the string hash seed).
  - Replaced upstream's `timeout` thread wrapper, which waited for the program to
    end before raising, with a deadline that `evaluate_ast` checks before each node
    (the `timeout` function is left in place, unused). A loop stops at the limit;
    one long built-in call still runs to its end. `ExecutionTimeoutError` is
    upgraded from `Exception` to `BaseException` so that `evaluate_python_code`'s
    own `except Exception` does not rewrap it as `InterpreterError`.

The behaviour of `evaluate_python_code`, the AST walker, the authorized-imports
allowlist's contents and matching, the dunder/operation/while limits, and
`BASE_PYTHON_TOOLS` is otherwise unchanged from upstream.

Everything else in this package is licensed under the MIT License (see LICENSE).
