> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hopx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Environment Variables

> Update or add sandbox environment variables without removing existing ones using the HopX VM Agent API. Merge new variables with existing ones, update specific variables, and manage environment configuration incrementally. Learn how to use PATCH /env endpoint to update variables without clearing others. Includes request examples and merge behavior.

Update or add environment variables. Merges with existing variables - only specified variables are updated, others are preserved.

## Endpoint

```
PATCH /env
```

## Request

### Headers

```
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json
```

### Body Parameters

| Parameter  | Type    | Required | Description                           |
| ---------- | ------- | -------- | ------------------------------------- |
| `env_vars` | object  | Yes      | Dictionary of variables to update/add |
| `merge`    | boolean | Yes      | Must be `true` for merge behavior     |

### Example Request

```bash theme={null}
curl -X PATCH https://sandbox_abc123xyz.hopx.dev/env \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "env_vars": {
      "DEBUG": "true",
      "NEW_VAR": "value"
    },
    "merge": true
  }'
```

## Response

### Success (204 No Content)

Empty response on success.

## Status Codes

| Code | Description                    |
| ---- | ------------------------------ |
| 204  | Variables updated successfully |
| 400  | Invalid request                |
| 401  | Unauthorized                   |

## Use Cases

### Add New Variables

```bash theme={null}
curl -X PATCH https://sandbox_abc123xyz.hopx.dev/env \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "env_vars": {
      "FEATURE_FLAG": "enabled"
    },
    "merge": true
  }'
```

## Related

* **SDK**: [sandbox.env.update()](/sdk/python/environment-variables#update) - Python SDK method
* [CLI Environment Variables](/cli/commands/env) - Environment variables from CLI

## Next Steps

* **[Get Environment Variables](/api/vm-agent/get-env)** - View all variables
* **[Set Environment Variables](/api/vm-agent/set-env)** - Replace all variables
