> ## 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.

# Set Environment Variables

> Replace all global environment variables in the sandbox using the HopX VM Agent API. Set or replace environment variables for code execution configuration. Learn how to use PUT /env endpoint to set all variables at once, handle variable values, and manage environment configuration. Includes request examples and response formats.

Replace all global environment variables in the sandbox. This operation clears existing variables and sets new ones.

<Warning>
  This replaces ALL environment variables. Use PATCH `/env` to merge variables instead.
</Warning>

## Endpoint

```
PUT /env
```

## Request

### Headers

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

### Body Parameters

| Parameter  | Type   | Required | Description                         |
| ---------- | ------ | -------- | ----------------------------------- |
| `env_vars` | object | Yes      | Dictionary of environment variables |

### Example Request

```bash theme={null}
curl -X PUT https://sandbox_abc123xyz.hopx.dev/env \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "env_vars": {
      "DATABASE_URL": "postgres://localhost/prod",
      "API_KEY": "sk-prod-123",
      "DEBUG": "false"
    }
  }'
```

## Response

### Success (204 No Content)

Empty response on success.

## Status Codes

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

## Use Cases

### Reset Variables

```bash theme={null}
curl -X PUT https://sandbox_abc123xyz.hopx.dev/env \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "env_vars": {
      "ENVIRONMENT": "production",
      "LOG_LEVEL": "info"
    }
  }'
```

## Related

* **SDK**: [sandbox.env.set()](/sdk/python/environment-variables#set) - 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
* **[Update Environment Variables](/api/vm-agent/update-env)** - Merge variables
* **[Clear Environment Variables](/api/vm-agent/clear-env)** - Remove all variables
