Skip to main content

ya-agent-environment

Environment abstractions for general agents.

ya-agent-environment provides the shared base interfaces used by YA agents:

  • Environment
  • FileOperator
  • Shell
  • ResourceRegistry
  • resumable resources
  • environment-owned temporary storage via tmp_dir and resolve_tmp_path()

The Python import package is ya_agent_environment.

Environment and File Backend Contracts

Environment owns temporary-directory configuration and lifecycle. While entered, env.tmp_dir exposes the agent-facing root (or None) and env.resolve_tmp_path(relative_path) safely resolves a contained path, rejecting absolute paths and parent traversal. Temporary paths are handled through the normal FileOperator methods; there is no separate temporary-file operator or routing API. Environment cleanup closes registered resources, the shell, and the file operator before _teardown() releases backend/container and temporary-directory resources. The same ordering is preserved after partial setup failures and during cancellation. The base class does not assume a filesystem backing store and never deletes _tmp_dir itself: custom environments must allocate their agent-facing temporary backend in _setup() and remove only owned storage in _teardown().

A FileOperator implementation exposes one logical path space by implementing its public abstract methods directly. read_bytes_stream() returns an AsyncIterator directly, so consume the returned iterator without awaiting the method call.

Workspace-backed concrete environments allocate owned temporary instances below .tmp/ya-agent-<id>. Each instance contains a self-ignoring .gitignore, and teardown removes only that owned instance. Custom environments remain responsible for allocating and tearing down their own temporary backend.

LocalFileOperator.walk_files() returns paths relative to default_path when possible and directly reusable absolute paths for explicitly allowed roots outside it. glob and grep may search those roots explicitly; root="." does not implicitly include temporary storage.

Bounded Output

Shared output-bounding policy lives in ya_agent_environment.output. It provides head/tail budget splitting, character and UTF-8 byte truncation, and incremental bounded text accumulation. Shell ingestion and SDK previews should reuse these helpers instead of defining independent truncation policies.

Shell Backend Contract

Custom Shell backends implement _create_process() and return an ExecutionHandle with stream, wait, and kill callbacks. Shell.execute() is the final public foreground boundary and must not be overridden: the base class owns process creation, timeout, cancellation, foreground/background registration, and session-reset cleanup. The foreground timeout budget begins before process creation, but shell-owned creation still resolves and terminates any eventual handle before reporting timeout. Class creation raises TypeError when final MRO resolution replaces execute(), so direct and mixin-based legacy overrides fail fast instead of silently bypassing lifecycle ownership; migrate their process creation into _create_process(). A wait callback must not report natural completion while owned descendants remain, and a kill callback must not return until backend execution is confirmed terminated; raising preserves the handle for a later reset retry. Backends must retain a stable execution identity through termination: a POSIX numeric PGID is no longer an ownership handle after its leader is reaped, so residual-group cleanup requires a live guardian or an equivalent platform-owned primitive.

Shell.start() returns a compact model-facing handle such as process-1. The handle is sequential and unique within the current shell session; a successful reset_background_processes() starts a fresh sequence. It is the only identifier accepted by wait_process(), kill_process(), stdin, signal, status, and completion APIs. It is not an OS PID, process-group ID, container exec identity, UUID, or durable cross-session key. Those backend ownership identities remain private in ExecutionHandle and transport-specific implementations. Foreground execution uses a separate private identity and never consumes the model-facing sequence. A failed reset retains both ownership state and the current sequence until termination is confirmed, so a live handle is never reused.

Development

This package is maintained as a workspace member in ya-mono.

uv run python -m pytest packages/ya-agent-environment/tests -vv
uv run python -m pyright
uv build --package ya-agent-environment -o dist

Metadata

Release files for ya-agent-environment 2.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ya-agent-environment 2.11.1
File Size Uploaded Provenance
ya_agent_environment-2.11.1.tar.gz 59.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ya-agent-environment 2.11.1
File Interpreter ABI Platform
ya_agent_environment-2.11.1-py3-none-any.whl Python 3 none any Details

Total release size: 97.6 kB

Release files / ya_agent_environment-2.11.1.tar.gz

Download URL ya_agent_environment-2.11.1.tar.gz
Size 59.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ac99f84b02d59f6e024bd9ed300672c7bf94d337dbd838ad9a7b33ba974603d6
BLAKE2b-256 checksum
How to use checksums
55a78dcaaabffbf2430796cba6130e4cdbbcb51587f1023870746a76e027959c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ya_agent_environment-2.11.1-py3-none-any.whl

Download URL ya_agent_environment-2.11.1-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
645c84a57c073821b88349acce4018aa14d316f2aa87aed36a915f88c26708df
BLAKE2b-256 checksum
How to use checksums
cfafa581abfbe4a2258a246a83e9414a616a770f4f2546f86c855fd69a44ffc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ya-agent-environment 2.11.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.11.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page