Skip to content

[Feature]: Allow SDK clients to configure environment variables for TerminalTool sessions #3812

Closed

Description

@bozhnyukAlex

Is there an existing feature request for this?

  • I have searched existing issues and feature requests, and this is not a duplicate.

Problem or Use Case

SDK clients need a supported way to provide additional environment variables to terminal execution.

Today TerminalTool sessions inherit sanitized_env() and can auto-export registered secrets when a command references them, but there is no explicit SDK client-facing API for passing non-LLM-controlled environment variables into the terminal session.

This is useful for dependency and runtime setup, for example:

  • package manager configuration such as UV_INDEX_URL, PIP_INDEX_URL, UV_CACHE_DIR,
    PIP_CACHE_DIR
  • proxy or mirror configuration
  • custom PATH / toolchain paths
  • project-specific non-secret runtime settings

The current workaround is to ask the agent/model to run export VAR=... or to prefix shell commands manually. That mixes client runtime configuration with LLM-generated actions and is less reliable than configuring the terminal environment at tool/session creation time.

Proposed Solution

Add a client-configured env option for TerminalTool / terminal session creation.

Important scope constraint: env should not be part of the LLM-facing tool action schema. The model should not generate or modify this field. It should be configured only by SDK clients through tool configuration / tool params.

Example API shape:

agent = Agent(
  llm=llm,
  tools=[
      Tool(
          name="TerminalTool",
          params={
              "env": {
                  "UV_INDEX_URL": "https://example.internal/simple",
                  "PIP_INDEX_URL": "https://example.internal/simple",
                  "UV_CACHE_DIR": "/workspace/.cache/uv",
              }
          },
      )
  ],
)

Expected behavior:

  • env is merged with sanitized_env() when creating the terminal session.
  • Client-provided values override inherited values where keys overlap.
  • The generated tool schema exposed to the model does not include env.
  • The environment is session-scoped and lives until terminal reset/close.
  • Invalid env var names should be rejected or ignored consistently.
  • Documentation should clarify that raw secret values passed through env become session-scoped, not command-scoped.

Alternatives Considered

  1. Ask the model to run export VAR=value before dependency commands.
    This works but makes runtime configuration depend on LLM behavior and persists state implicitly in the shell session.

  2. Prefix each command with VAR=value command.
    This is repetitive, brittle for long commands, and again requires the model or client prompt to manage environment details.

  3. Add env to TerminalAction.
    This would be more flexible per command, but it would expose environment control to the LLM-facing tool schema and could increase security/persistence ambiguity. For this use case, client-configured session-level env is preferable.

Priority / Severity

Medium - Would improve experience

Estimated Scope

Medium - New feature with moderate complexity

Feature Area

  • Agent API / Core functionality
  • Tools / Tool system
  • Skills / Plugins
  • Agent Server
  • Workspace management
  • Configuration / Settings
  • Examples / Templates
  • Documentation
  • Testing / Development tools
  • Performance / Optimization
  • Integrations (GitHub, APIs, etc.)
  • Other

Technical Implementation Ideas (Optional)

Implementation sketch:

  • Add an optional env: Mapping[str, str] | None parameter to TerminalTool.create() /
    TerminalExecutor.
  • Store it as executor/session configuration, not as TerminalAction.
  • Merge it with sanitized_env() at terminal backend initialization.
  • Apply consistently across subprocess, tmux, tmux pane pool, and PowerShell backends.
  • Add regression tests verifying:
    • client-configured env is visible inside terminal commands;
    • env is not present in the model-facing tool action schema;
    • reset/close behavior is documented and predictable;
    • invalid env var names are handled safely.
  • Consider whether the agent-server bash API should also support a similar client-
    controlled env field, or whether this should be limited to SDK TerminalTool sessions
    first.

Additional Context

Activity

  1. added
    enhancement
    on Jun 20, 2026
  2. self-assigned this
    on Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions