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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0805fea1d23f923a53521a5194c0d15b774d08c78f9d9aa6d5ea4d81b521503
|
|
| MD5 |
1ba808dcb7204e42851972b881bd4cba
|
|
| BLAKE2b-256 |
a3625afa02592d9e2395d4aa2f6855c70f4edc64f35c499827dc1a26bf319bb0
|
Provenance
The following attestation bundles were made for agent_venv-0.1.0.tar.gz:
Publisher:
release-python.yml on JacobLinCool/agent-venv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_venv-0.1.0.tar.gz -
Subject digest:
e0805fea1d23f923a53521a5194c0d15b774d08c78f9d9aa6d5ea4d81b521503 - Sigstore transparency entry: 1492251675
- Sigstore integration time:
-
Permalink:
JacobLinCool/agent-venv@77c3893fa0b5d248a5766ef230169206c6d01eda -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/JacobLinCool
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@77c3893fa0b5d248a5766ef230169206c6d01eda -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09ea05840179aff8e4754ecbe97b909cf66e8c2b35b2d2fcb0900c727f2735bf
|
|
| MD5 |
624c300b21190cb2b5cab1756f29e409
|
|
| BLAKE2b-256 |
84a2e24018e8a6ee0573bf451cf73b3f58cd7ca64de58fe3c9822fd4a0f8338b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_venv-0.1.0-py3-none-any.whl -
Subject digest:
09ea05840179aff8e4754ecbe97b909cf66e8c2b35b2d2fcb0900c727f2735bf - Sigstore transparency entry: 1492251859
- Sigstore integration time:
-
Permalink:
JacobLinCool/agent-venv@77c3893fa0b5d248a5766ef230169206c6d01eda -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/JacobLinCool
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@77c3893fa0b5d248a5766ef230169206c6d01eda -
Trigger Event:
push
-
Statement type: