Download plans/2025-09-07-shell-env-variable-support-v1.md from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/plans/2025-09-07-shell-env-variable-support-v1.md
- Command line
-
hf download hf://SaylorTwift/forgecode/plans/2025-09-07-shell-env-variable-support-v1.md
-
curl -L -o 2025-09-07-shell-env-variable-support-v1.md https://huggingface.co/SaylorTwift/forgecode/resolve/main/plans/2025-09-07-shell-env-variable-support-v1.md
Shell Tool Environment Variable Support
Objective
Add environment variable support to the shell tool, allowing agents to specify environment variable names that should be set before executing commands. The infrastructure will read these environment variables from the system and apply them during command execution.
Implementation Plan
Task 1. Update Shell Tool Domain Model
Extend theShellstruct incrates/forge_domain/src/tools.rsto include an optionalenvfield that accepts a vector of environment variable names. This field will specify which environment variables should be passed to the command execution environment.Task 2. Update CommandInfra Interface
Modify theCommandInfratrait incrates/forge_services/src/infra.rsto accept environment variable names in theexecute_commandandexecute_command_rawmethods. This involves adding a new parameterenv_vars: Option<Vec<String>>to both methods.Task 3. Update ShellService Interface
Extend theShellServicetrait incrates/forge_app/src/services.rsto accept environment variable names in theexecutemethod. Addenv_vars: Option<Vec<String>>parameter to maintain consistency with the updated CommandInfra interface.Task 4. Update Shell Service Implementation
Modify theForgeShellimplementation incrates/forge_services/src/tool_services/shell.rsto pass environment variable names to the infrastructure layer. Update theexecutemethod to forward the env_vars parameter to the command infrastructure.Task 5. Update Command Executor Implementation
Enhance theForgeCommandExecutorServiceincrates/forge_infra/src/executor.rsto read specified environment variables from the system and apply them to the command execution context. Modify theprepare_commandmethod to set the requested environment variables on the Command instance.Task 6. Update Tool Operation Processing
Modify the shell tool operation handling incrates/forge_app/src/operation.rsandcrates/forge_app/src/tool_executor.rsto extract environment variable names from the Shell tool input and pass them through the service chain.Task 7. Update Infrastructure Implementations
Update all CommandInfra implementations to support the new environment variable parameter, including the main implementation incrates/forge_infra/src/forge_infra.rsand any test implementations incrates/forge_services/src/attachment.rs.Task 8. Add Comprehensive Test Coverage
Create tests to verify environment variable functionality works correctly, including tests for missing environment variables, empty env lists, and successful environment variable application during command execution.
Verification Criteria
- Environment variable names can be specified in shell tool calls through the new
envfield - Specified environment variables are properly read from the system and applied to command execution
- Commands execute successfully with the requested environment variables available
- Missing environment variables are handled gracefully without causing command failures
- All existing shell tool functionality continues to work unchanged
- Test suite passes with comprehensive coverage of the new environment variable feature
Potential Risks and Mitigations
Breaking API Changes
Mitigation: Use optional parameters and default values to maintain backward compatibility with existing shell tool usageEnvironment Variable Security
Mitigation: Only read specified environment variables by name rather than exposing the entire environment to prevent unintended information leakageMissing Environment Variables
Mitigation: Handle missing environment variables gracefully by either skipping them or providing clear error messages, depending on the desired behaviorPerformance Impact
Mitigation: Only read environment variables when explicitly requested, avoiding unnecessary system calls when the env field is not provided
Alternative Approaches
Direct Environment Variable Values: Allow agents to specify environment variable values directly instead of just names
- Trade-offs: More flexible but potentially less secure, as it would allow agents to set arbitrary values rather than using system-defined values
Environment Variable Validation: Implement allowlists or validation for which environment variables can be accessed
- Trade-offs: Enhanced security but increased complexity and potential limitations for legitimate use cases
Separate Environment Tool: Create a dedicated tool for environment variable management instead of extending the shell tool
- Trade-offs: Cleaner separation of concerns but additional complexity for users who need both shell execution and environment variable access