Skip to main content

agent-venv (Python)

Python implementation of agent-venv. See the root README for the project overview and the spec/ directory for the cross-language contract.

Install

pip install agent-venv
# or, from this monorepo:
uv pip install -e .

Requires Python 3.10+.

Layer 1 — generic environment

import subprocess
from agent_venv import Environment, EnvironmentSpec

# Ephemeral: cleaned up on context exit
with Environment.ephemeral(
    EnvironmentSpec(env_overrides={"CLAUDE_CONFIG_DIR": "$EPHEMERAL_HOME"})
) as env:
    subprocess.run(
        ["claude", "--print", "hi"],
        env={**os.environ, **env.env_overrides},
        cwd="/anywhere",
    )

# Persistent: keyed by name, survives the process
env = Environment.create_or_attach(
    "myapp-skill-x",
    EnvironmentSpec(env_overrides={"CLAUDE_CONFIG_DIR": "$EPHEMERAL_HOME"}),
)
print(env.path, env.env_overrides)
# ...later, from anywhere...
env = Environment.attach("myapp-skill-x")

The library never spawns the agent. The caller does. The library only manages the profile dir and the env vars to point the agent at it.

Layer 2 — built-in adapters

ClaudeCode and Codex are thin wrappers that produce the right EnvironmentSpec, including reading host credentials so the agent runs under your subscription.

from agent_venv import Environment, ClaudeCode

with Environment.ephemeral(adapter=ClaudeCode()) as env:
    subprocess.run(
        ["claude", "--print", "hi"],
        env={**os.environ, **env.env_overrides},
    )

The adapter copies your ~/.claude/.credentials.json (or macOS Keychain entry) into the new profile with mode 0600. The original is not modified.

Persistent registry

Persistent envs live under $XDG_DATA_HOME/agent-venv/envs/ (or ~/.local/share/agent-venv/envs/). Override with AGENT_VENV_REGISTRY_ROOT env var or per-call registry_root=.

Environment.list()                          # all persistent env names
Environment.attach("name")                  # raises if missing
Environment.destroy_by_name("name")         # removes from disk + registry
env.refresh_credentials()                   # re-copy host credentials

Async

from agent_venv import AsyncEnvironment

async with await AsyncEnvironment.ephemeral(adapter=ClaudeCode()) as env:
    ...

Errors

from agent_venv import errors

try:
    Environment.attach("missing")
except errors.EnvironmentNotFoundError as exc:
    print(exc.kind, exc)  # "EnvironmentNotFound", "..."

All errors subclass errors.AgentVenvError and carry a kind: str matching the spec.

Conformance

python -m agent_venv.conformance < requests.ndjson

See spec/conformance-protocol.md.

Metadata

Release files for agent-venv 0.1.0

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

Source distribution (sdist)

Source distribution for agent-venv 0.1.0
File Size Uploaded
agent_venv-0.1.0.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-venv 0.1.0
File Interpreter ABI Platform
agent_venv-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.5 kB

Release files / agent_venv-0.1.0.tar.gz

Download URL agent_venv-0.1.0.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e0805fea1d23f923a53521a5194c0d15b774d08c78f9d9aa6d5ea4d81b521503
BLAKE2b-256 checksum
How to use checksums
a3625afa02592d9e2395d4aa2f6855c70f4edc64f35c499827dc1a26bf319bb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 10, 2026.

Transparency log

Release files / agent_venv-0.1.0-py3-none-any.whl

Download URL agent_venv-0.1.0-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09ea05840179aff8e4754ecbe97b909cf66e8c2b35b2d2fcb0900c727f2735bf
BLAKE2b-256 checksum
How to use checksums
84a2e24018e8a6ee0573bf451cf73b3f58cd7ca64de58fe3c9822fd4a0f8338b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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