Skip to content

Python Execution Environment

Zene provides an isolated and safe environment for executing Python code generated by the Agent.

1. The Virtual Environment (.venv)

Zene automatically manages a Python virtual environment in the project root to prevent host system pollution.

  • Auto-Creation: Creates .venv if missing.
  • Performance (uv): Prioritizes uv for sub-millisecond setup; falls back to venv.
  • Isolation: Each script runs within this project-scoped environment.

2. Session Isolation

Environment variables are managed at the Session level:

  • Variables set via set_env are stored in the session state.
  • They are injected only into the child processes (Command::envs).
  • The server host environment remains untouched and thread-safe.

3. Tools API

  • run_python: Executes a script within the .venv.
  • set_env: Persists a key-value pair for the current session.
  • get_env: Retrieves a variable from the session context.

4. Safety & Limits

  • Timeout: Hard 60-second limit on all scripts.
  • Standard Input: stdin is closed to prevent hanging on interactive prompts (e.g., input()).
  • Cleanup: Ephemeral files and dependencies are tracked per project.

5. Security Best Practices

  1. Secrets: Use set_env instead of hardcoding API keys.
  2. Dependencies: Use requirements.txt; Zene will automatically attempt to resolve missing packages.
  3. Non-interactive: Ensure scripts are fully automated.

Released under the MIT License.