Elide 1.0.0-alpha10 Help

Intro: Env Variables

Reading environment variables from JavaScript and Python

Many applications use environment variables to pass small bits of data between invocations, or across process boundaries.

As part of Elide's job in unifying multiple languages for use in one program, environment variable access is made uniform across all languages:

  • Environment is subject to policy. By default, code cannot see system environment variables in Elide; this is a big difference with other runtimes, so it bears repeating below.

  • Environment is loaded uniformly. Support for features like dotenv files is cross-language in Elide. If you see a variable in JavaScript, you will see it as well in Python, Ruby, and so on.

Before you start

Before running the code below, you'll need to make sure the following is true:

  • Elide is installed

  • The elide binary is executable

  • The elide binary is on your PATH, or otherwise referenced in absolute form

Reading environment variables

We're going to try out Elide's policies with regard to reading host environment variables.

  1. Start an interactive session; Elide defaults to JavaScript, so you should get a JavaScript prompt:

    export ELIDE_TESTING="hello" elide repl elide (js) >
  2. Elide provides the process object, just like Node:

    elide (js) > process.env.ELIDE_TESTING undefined

    Our ELIDE_TESTING environment variable isn't showing up! That's because Elide forbids access to environment variables by default.

  3. Now, let's run the REPL session again, but with access to host environment:

    elide repl --allow:host-env elide (js) > process.env.ELIDE_TESTING hello

    Neat! We can see the environment variable.

  4. Now let's try Python:

    elide repl --python elide (python) > import os; os.environ Environ(ELIDE_INTERNAL, ELIDE_ROOT, NODE_ENV)
  5. And with environment access enabled:

    elide repl --python --allow:host-env elide (python) > import os; os.environ Environ(ANDROID_HOME, AWS_ACCESS_KEY_ID, ... ELIDE_TESTING, ...)

    Of course, the accessing variable returns the expected value:

    elide repl --python --allow:host-env elide (python) > import os; os.environ["ELIDE_TESTING"] 'hello'

What you've learned

In this tutorial, you learned about Elide's policy enforcement around env variable access, and how it interoperates with JavaScript and Python.

Last modified: 11 May 2024