> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/guides-and-quickstarts/releases-and-environments/assign-and-secure-an-environment.md).

# Assign and secure an environment

Share an environment with the people who need its configuration. Assign an appropriate role, then attach the environment to workflows that need its variables.

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2F39RKfPAkC9KcFgVJsqQy%2FG076.mp4?alt=media&token=291ea2f3-ff5a-415d-be03-0d134db6fe6b>" %}

## Before you start

Create the environment and its stage values first using [Create environment variables](https://docs.stackai.com/guides-and-quickstarts/releases-and-environments/create-environment-variables.md). Identify both the workflow that needs the variables and the people who need to manage them. A workflow needing a value does not mean every team member needs permission to edit or reveal it.

You need permission to manage the environment and its access list.

## Set environment permissions

Open Environments with the account whose access you need to understand.

![Environments visible to the member](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/dOPfXAll4JgFBnvnkaRA/assets/g076-g076-01-baseline.png)

Note which environments are visible before changing permissions.

As an administrator, open the environment's Permissions page and review Viewer, Editor, and Admin roles.

![Environment permission roles](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/PxWBpYRFHtqLQXARpzY6/assets/g076-g076-02-roles.png)

Choose the role required for the person's responsibilities.

Select the intended organization member, choose the role, and add the grant.

![Member and role grant](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/hHMsyAEkKO6kKmzQ5npW/assets/g076-g076-03-granted.png)

Confirm the saved member and role in the permissions table.

Have the member refresh Environments with their own account.

![Shared environment in the member view](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/ONQUqnX1NvT8Oaghwa0q/assets/g076-g076-04-visible.png)

Confirm that the specifically shared environment is visible.

Open the environment with the Viewer account and inspect the available controls.

![Viewer account management controls](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/0kqz9wJgLq47sRSn2wdr/assets/g076-g076-05-restricted.png)

Review restrictions on creating variables, revealing secrets, editing, and deleting rather than relying only on the role name.

## Use variables in a workflow

In the workflow, open More options → Environments and choose the required environment.

![Workflow environment assignment](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/GTKywvrL4PMzCk75aCoW/assets/g076-g076-06-assign.png)

Its variables then become available to the workflow's reference picker.

Open the field that needs a variable and use the reference picker to select it under Environment Variables.

![Environment Variables reference picker](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/uTZikWtzkgTIZxVU3gCr/assets/g076-g076-07-picker.png)

Insert a live reference rather than typing a similar-looking variable name as plain text.

Review the field after inserting the variable and remove any unused picker trigger.

![Field with inserted environment reference](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/SndJLSvcVvHuuhN2UE3f/assets/g076-g076-08-token.png)

Save the workflow with the intended instruction and reference intact.

Run the workflow and inspect the resolved value in its result where appropriate.

![Workflow result used to check stage configuration](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/YGmL6dDEY3Nfr5AMhQDN/assets/g076-g076-09-result.png)

Confirm that it corresponds to the stage being used without exposing secrets in user-facing output.

## Remove environment access

When access is no longer required, remove the intended permission entry as an administrator.

![Environment permission removal](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/ejsXIj1ilkuKNnjSy2rh/assets/g076-g076-10-revoked.png)

Check the member carefully before deleting the grant.

Have the affected member refresh the environment view.

![Member environment view after access removal](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/v47kAluOLdLpNb4kIssl/assets/g076-g076-11-denied.png)

Confirm the resulting access state, taking any other organization or group grants into account.

## Important behavior

Environment roles control which management actions a member can perform. A Viewer cannot edit the environment.

Do not send a secret variable to a user-facing output. Verify it through the operation that needs it.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/guides-and-quickstarts/releases-and-environments/assign-and-secure-an-environment.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
