Course menuForge Cloud

Level 1 · Lesson 3

Lock the key in the safe

Goal of this lesson

Store the API Ninjas key as an encrypted variable before any code uses it, so it never sits in a file, a commit or the browser.

About 10 min4 steps

Behind, or starting here? Download the code as it should be before this lesson, or in the course workspace run course-catch-up level-1/after-02-work-from-your-laptop in the folder above your app. It offers to bring your own app folder to this point and keeps its app id (the id: line in manifest.yml, which links the code to your app on the site), so it stays the same app. Your old files are kept in a copy next to it.

Lesson 4 calls API Ninjas, and every call needs your key. A workshop keeps keys in a key safe, not on the counter; your app keeps its key in an encrypted variable. It goes in first, before there is any code that could tempt you to paste it in. This lesson changes no files.

Step 1: Put the key in the key safe

Runs in the Atlassian cloud

Environment variablein the workshop: the key safe

An environment variable is a named value stored with the app, per environment. Functions read it as process.env.NAME. With --encrypt, the value is stored encrypted and forge variables list never shows it again. UI code in the browser cannot read variables at all, which is one more reason the call to API Ninjas happens in a function.

In the workshop Account keys and booking codes go in the key safe, never in the code.

Further reading, optional: Atlassian docs on forge variables (opens in a new tab)

See this on the Level 1 chart, in the step that reads the key from the encrypted variable.

Your terminalforge variables set --encryptYour functionprocess.env.API_NINJAS_KEYa filea committhe browserthe keyat run timekey safean encrypted variable, stored with the app

In the app folder, run:

RunTerminal
forge variables set --encrypt API_NINJAS_KEY

The CLI asks for the value and hides what you type: when you paste the key, nothing appears, not even dots. That is normal. Paste it once, press Enter, and don’t paste it anywhere else, such as an AI chat panel next to the terminal. Because the value is never part of the command, it stays out of your shell history too: the list of past commands your terminal saves to a file, which anyone using your computer could read.

A sketch of a terminal, drawn from a real run of Forge CLI in October 2026. Newer versions may word the lines a little differently.
Stuck?One common problem, and its fix
  • I set or changed a variable

    Variables reach your functions with the next deploy:

    RunTerminal
    forge variables list
    forge deploy

    Variables belong to one environment. Unless you add -e followed by an environment name (such as -e production), both commands use development.

    Open in the FAQ

Step 2: Check it is there, and hidden

RunTerminal
forge variables list

You should see API_NINJAS_KEY with a tick under Encrypted? and its value shown as ****. Nobody, including you, can read it back from here. If you ever need to change it, set it again.

Step 3: Deploy so functions can read it

The CLI reminds you of this itself: a new or changed variable reaches functions only with the next deploy.

RunTerminal
forge deploy
Stuck?One common problem, and its fix
  • I set or changed a variable

    Variables reach your functions with the next deploy:

    RunTerminal
    forge variables list
    forge deploy

    Variables belong to one environment. Unless you add -e followed by an environment name (such as -e production), both commands use development.

    Open in the FAQ

Step 4: Optional: give the tunnel the key too

While forge tunnel runs, your laptop runs the code, and it reads variables from your terminal (its shell, the program that reads what you type), not from the key safe. Forge looks for the name with FORGE_USER_VAR_ in front.

In bash or zsh (the usual shells on macOS, Linux and in the course workspace), this asks for the key without showing it and keeps it for this terminal only. On Windows, use the tunnel from the course workspace in Docker, whose terminal runs bash:

RunTerminal
read -s FORGE_USER_VAR_API_NINJAS_KEY && export FORGE_USER_VAR_API_NINJAS_KEY

The line is two commands joined by &&, which means “do the second only if the first worked”:

  • read -s waits for you to type or paste a value and stores it under the name that follows. The -s stands for silent: what you paste is not shown.
  • export makes that value visible to programs started from this terminal, such as forge tunnel. Without it, only the terminal itself would know the value.

Close the terminal and the value is gone, which is what you want for a key.

After you press Enter, the cursor waits on an empty line with no message: it is waiting for the key. Paste the key (nothing appears) and press Enter again.

Start forge tunnel from the same terminal.

Type at least two letters.