function setEnv(string calldata key, string calldata value) external;


Set an environment variable key=value.

ℹ️ Note

Environment variables set by a process are only accessible by itself and its child processes. Thus, calling setEnv will only modify environment variables of the currently running forge process, and won’t affect the shell (forge’s parent process), i.e., the they won’t persist after the forge process exit.


  • The environment variable key can’t be empty.
  • The environment variable key can’t contain the equal sign = or the NUL character \0.
  • The environment variable value can’t contain the NUL character \0.


string memory key = "hello";
string memory val = "world";
cheats.setEnv(key, val);