# Update an environment

> Rename it, add or replace variables with env, remove them with unset. Variables left out keep their values. Sandboxes already started keep the values they started with.

`PATCH https://api.zavu.dev/v1/sandbox-environments/{environmentId}`

Rename it, add or replace variables with `env`, remove them with `unset`. Variables left out keep their values. Sandboxes already started keep the values they started with.

## Parameters

- `environmentId` (path, string, required): Sandbox environment ID.

## Body

- `name` (string)
- `env` (object): Variables to add or replace. A variable left out keeps its value.
  - `{key}` (string)
- `unset` (string[]): Variables to remove.

## Responses

### 200

Updated.

- `environment` (object, required): A named set of environment variables to start sandboxes with. Values are encrypted at rest and never returned.
  - `id` (string, required)
  - `name` (string, required)
  - `variables` (object[], required): Each variable's name and the last four characters of its value.
    - `key` (string, required)
    - `last4` (string, required)
  - `createdAt` (string<date-time>, required)
  - `updatedAt` (string<date-time>, required)

### 400

Invalid name or variables, or an empty body.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Environment not found, or it belongs to another project.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 409

`conflict`: another environment has that name.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X PATCH "https://api.zavu.dev/v1/sandbox-environments/environment_abc123" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "env": {
    "FEATURE_FLAG": "1"
  },
  "unset": [
    "OLD_TOKEN"
  ]
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.sandboxes.environments.update("environment_abc123", {
  env: {
    FEATURE_FLAG: "1",
  },
  unset: [
    "OLD_TOKEN",
  ],
});

console.log(result);
```
