---
schema_version: "1"
id: e37a95e764ee1877c0367e9ff9e311b45beb1e0a4786a72317405f15312ffb29
title: Manage Function Environment Variables
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-functions/functions/guide/dev-guide/envvars.md
canonical_url: https://developer.salesforce.com/docs/platform/functions/guide/envvars.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 87048016aa96f7c4f9388801cdcb0b92ee9445cfa22c67a32e3a2d4d084a8d8b
products:
  - Salesforce Functions
---
# Manage Function Environment Variables

Use environment variables to represent values your function needs at runtime, such as securely storing credentials or configuration details.
Environment variables are securely stored in the Salesforce Functions Compute Cloud, and can be accessed by your function code as system variables.

## Set Environment Variables in Compute Environments

To manage environment variables, use the `sf env var` CLI commands. These commands require specifying a Compute Environment where the environment variables are set or unset.

To set an environment variable in a compute environment, use `sf env var set`:

```sh
sf env var set GITHUB_USERNAME=stevesmith -e MyComputeEnv
```

Set multiple environment variables in a single command:

```sh
sf env var set USER1=joe USER2=steve -e MyComputeEnv
```

Use `sf env var get` or `sf env var list` to inspect what environment variables are set to in a given compute environment:

```sh
sf env var get GITHUB_USERNAME -e MyComputeEnv
stevesmith

$ sf env var list -e MyComputeEnv
Key             Value
GITHUB_USERNAME stevesmith
ANOTHER_VAR     anothervalue
```

To remove an environment variable from a compute environment, use the `sf env var unset` command:

```sh
sf env var unset GITHUB_USERNAME -e MyComputeEnv
```

## Set Environment Variables for Local Invocation

To test your function locally, use `sf run function start` with local environment variables your function can access.

```sh
sf run function start GITHUB_USERNAME
```

## Access Environment Variables in Your Function Code

Environment variables appear as standard system variables when your function runs. Use standard system variable APIs provided by your programming language to access environment variables.

For example, to access the `GITHUB_USERNAME` environment variable in a JavaScript function, use the `process.env`:

```js
let userName = process.env.GITHUB_USERNAME;
```

To access `GITHUB_USERNAME` in a Java Function, use `System.getenv()`:

```java
String userName = System.getenv("GITHUB_USERNAME");
```
