Temporal Workflows using process.env?

Do workflows have access to process.env? I can see that activities do but I get process is undefined when trying to access them.

If not, is there any way to get around it? I’m in the middle of converting an existing monorepo over and making varying parts of the codebase workflows was only possible if it was fine that it was using process.env.

Hello!

TypeScript Workflows are executed in a “deterministic sandbox”, which make sure that Workflows can’t use any module that is inherently non-deterministic. See this doc page for more details on that subject.

Now, environment variables are indeed non-deterministic, since they may have different values for different instances of the Workflow Worker. Therefore, you can not access environment variables from your Workflow code.

In practice, this is rarely an issue anyway, since Workflow themselves rarely have a need for that kind of configuration. Suppose for example that you might have used some environment variable to provide connection details to some application database or some remote service (service’s URL, credentials, etc). The connection to that external/remote service will be established by some Activities, and only those Activities need these environment variables. The Workflow itself, however, has no need to know about any of this.

Still, should you really have a use case where the Workflow require some runtime configuration, then you may consider having the Workflow execute an Activity (possibly a local activity) that returns the value of the corresponding environment variable. That Activity will run only once, after which these values will get persisted to the Workflow History, thus ensuring that the same values will be used on eventual replay.

Makes perfect sense. I could just have that run in activities if needed, or make it a conditional. Thanks for the reply!