# Passing os.environ in ray-decorated functions

**URL:** <https://discuss.ray.io/t/passing-os-environ-in-ray-decorated-functions/3828>\
**Category:** Ray Core\
**Created:** [October 15, 2021, 2:44pm UTC](https://discuss.ray.io/t/passing-os-environ-in-ray-decorated-functions/3828 "2021-10-15T14:44:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivvv](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ivvv/32/1607_2.png) [@ivvv](https://discuss.ray.io/u/ivvv)\
**Post date:** [October 15, 2021, 2:44pm UTC](https://discuss.ray.io/t/passing-os-environ-in-ray-decorated-functions/3828/1 "2021-10-15T14:44:18Z")

</div>

Hello,

Here is an example code, where in the main part I set up an `os.environ` which I need in my function, decorated with @ray.remote:

```auto
import os
import ray

ray.init()

@ray.remote
def f(x):
    print (os.environ['MYTEST'])
    return x * x

# let's set an environ variable
os.environ['MYTEST'] = 'testing'
futures = [f.remote(i) for i in range(4)]
print(ray.get(futures)) # [0, 1, 4, 9]

```

If I call f(i) without the decorations, I have access to os.environ[‘MYTEST’], with `@ray.remote` I don’t.

Is there an elegant way to access “globals” from the main part of the code within ray-decorated functions? I can probably pass `os.environ` as an argument to f(x) but it’s not that elegant.

---

<div class="post-metadata">

**Author:** ![ericl](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ericl/32/133_2.png) [@ericl](https://discuss.ray.io/u/ericl)\
**Post date:** [October 18, 2021, 11:21pm UTC](https://discuss.ray.io/t/passing-os-environ-in-ray-decorated-functions/3828/2 "2021-10-18T23:21:17Z")

</div>

If you need access to a “global” config, one way is to use a named actor, e.g., “a = Actor.options(name=“global”).remote()”. Then, any task can retrieve a handle to that actor `a` with `ray.get_actor("global")` and query the config.

The other option is to pass the config explicitly as an arg as you mentioned.
