Skip to main content

Run coding-agent CLIs in an isolated profile and workspace.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_venv-0.1.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_venv-0.1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file agent_venv-0.1.0.tar.gz.

File metadata

  • Download URL: agent_venv-0.1.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agent_venv-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0805fea1d23f923a53521a5194c0d15b774d08c78f9d9aa6d5ea4d81b521503
MD5 1ba808dcb7204e42851972b881bd4cba
BLAKE2b-256 a3625afa02592d9e2395d4aa2f6855c70f4edc64f35c499827dc1a26bf319bb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_venv-0.1.0.tar.gz:

Publisher: release-python.yml on JacobLinCool/agent-venv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_venv-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agent_venv-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agent_venv-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09ea05840179aff8e4754ecbe97b909cf66e8c2b35b2d2fcb0900c727f2735bf
MD5 624c300b21190cb2b5cab1756f29e409
BLAKE2b-256 84a2e24018e8a6ee0573bf451cf73b3f58cd7ca64de58fe3c9822fd4a0f8338b

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_venv-0.1.0-py3-none-any.whl:

Publisher: release-python.yml on JacobLinCool/agent-venv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page