---
title: "Rollback Environment"
method: POST
path: "/agents/{namespace_slug}/{agent_name}/environments/{env_name}/rollback"
tags: ["Branches"]
---

# Rollback Environment

`POST /agents/{namespace_slug}/{agent_name}/environments/{env_name}/rollback`

Roll back an environment to a previous version.

    Resolves environment to branch via branch rules.
    Only works for environments with a single, literal branch rule (no wildcards).

    Key behavior:
    - EnvVar table is NOT modified (remains pending state for next deploy)
    - Uses Version.secrets_snapshot as deployed state

## Path parameters

- `namespace_slug` string, required
- `agent_name` string, required
- `env_name` string, required

## Request body

- RollbackRequest — Request model for rolling back a branch.
  - `target_version_id` string, nullable — Version ID to rollback to (defaults to previous version if not specified)

## Response `200`

Successful Response

- RollbackResponse — Response from a rollback operation.
  - `branch_id` string, required — Branch ID
  - `from_git_hash` string, required — Git hash of the previous version
  - `from_version_id` string, required — Version ID that was rolled back FROM
  - `message` string, required — Human-readable status message
  - `to_git_hash` string, required — Git hash of the target version
  - `to_version_id` string, required — Version ID that was rolled back TO
  - `version_status` 'DEPLOYING' | 'ACTIVE' | 'FAILED' | 'UNHEALTHY' | 'DRAINING' | 'RETIRED' | 'ROLLED_BACK', required — Status of a version in its lifecycle.

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/terminaluse/apis/sb0-api.md) · [All operations](https://skmtc.dev/terminaluse/apis/sb0-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/terminaluse/sb0-api/revisions/f24a474dc415/schema)
