---
title: "Cloud environment variables | Grafana Cloud documentation"
description: "You can use Environment Variables to store sensitive (and non-sensitive) information that you want to reference in your cloud test-scripts."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Cloud environment variables

Environment Variables are key-value pairs that you configure at the organization level.

The cloud service encrypts all values before storing them in our database, and they remain encrypted until needed for a test run. If you reference a variable in a test script, the cloud service inserts the value of the variable on the server that runs the test.

You can use Environment Variables to store sensitive (and non-sensitive) information that you want to reference in your test-scripts. Managing environment variables in one central place brings the following benefits:

- Reduced data exposure
- An easier way to re-use and change values across different test scripts.

> Note
> 
> Changes to an environment variable don’t apply to test runs that have already started.

## Manage environment variables

Only owners and admins can create, modify, and delete environment variables. If you have appropriate permission, you can manage environment variables with these steps:

1. Log in to your Grafana Cloud account.
2. Go to **Testing &amp; synthetics &gt; Performance &gt; Settings**.
3. Under **Execution resources**, click **Environment variables**.

### Rules for environment variable names

The following restrictions apply to environment variable names:

- Names can contain only alphanumeric characters (`[a-z]`, `[A-Z]`, `[0-9]`) and underscores (`_`). Spaces are not allowed.
- Names must not start with the `K6_CLOUD` prefix.
- Names must not start with a number.
- Names are **case insensitive**.
- Names must be unique.

### Declare a new environment variable

1. Give your Environment Variable a `name`, then enter the respective Value.
2. Optionally, add a brief description.
3. Select **Submit**.

## Access environment variables

If you create an Environment Variable on k6 Cloud, you can reference it in your k6 script through the \_\_ENV variable, as you would with other [k6 Environment Variables](/docs/k6/latest/using-k6/environment-variables/)

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import http from 'k6/http';
import { sleep } from 'k6';

export default function () {
  const params = {
    headers: { Authorization: __ENV.AUTH_TOKEN },
  };
  const res = http.get(__ENV.SERVICE_URL, params);
  sleep(1);
}
```

> Warning
> 
> The current environment variables implementation doesn’t prevent printing values to the log (or restrict exposing a variable any other way). You should avoid printing sensitive data to the log intentionally.

## Order of precedence

When starting tests with `k6 cloud run`, environment variables set via CLI flag `--env` and environment variables set in the cloud are combined and used together to run the test. If you set an environment variable via the CLI and also declare it in the cloud, the value set via the CLI takes precedence.

> Warning
> 
> Environment variables set via CLI flag are stored in the archive as plain data.
