Repository navigation
Description
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:
envis merged withsanitized_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
-
Ask the model to run
export VAR=valuebefore dependency commands.
This works but makes runtime configuration depend on LLM behavior and persists state implicitly in the shell session. -
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. -
Add
envtoTerminalAction.
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-levelenvis 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] | Noneparameter toTerminalTool.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
envis visible inside terminal commands; envis not present in the model-facing tool action schema;- reset/close behavior is documented and predictable;
- invalid env var names are handled safely.
- client-configured
- Consider whether the agent-server bash API should also support a similar client-
controlled env field, or whether this should be limited to SDKTerminalToolsessions
first.
Additional Context
execute_bashtool should be able to inherent current env vars #243 addressed inherited parent env forexecute_bash, but does not provide an explicit SDK client API for configuring terminal env.- Command-scoped secrets persist across TerminalExecutor session boundaries #2944 discusses the security implications of command-scoped secrets persisting in a persistent terminal session. This proposal avoids adding
envto the LLM-generated action schema and treats client-provided env as session-scoped. - MCP tool parameters do not expand secrets/environment variables (unlike terminal commands) #3277 / fix: expand secrets in MCP tool parameters #3278 handled secret/environment expansion for MCP tool parameters, showing similar env/secret propagation concerns across tools.
- feat(tools): InteractiveTerminalToolSet — exec_command + write_stdin with yield_time_ms #3806 / Track PR #3806: InteractiveTerminalToolSet — exec_command + write_stdin with yield_time_ms #3807 introduce an
InteractiveTerminalToolSet; the PR currently documents that secret injection is not implemented there, which suggests terminal env propagation is still an active design area.
Activity