What the agent does
- Lists the environments of the project and their last deployment.
- Checks the pull request behind each preview in your Git provider.
- Deletes the previews whose pull request is merged or closed, or that are idle for 7 days.
- Reports what it deleted.
What the policy allows
The agent can
- Find the organization, project and environment by name
- Read the environments of the project, except environment variables
- Delete a whole environment of the project, unless it is protected
The agent cannot
- Delete production, staging or any protected environment
- Delete a single service, a database or the project
- Delete anything in another project
- Deploy, stop or change anything
401 Unauthorized.
The policy
Copy it, then replace eachREPLACE_WITH_... value with a real ID from your organization.
clean-up-preview-environments.rego
You can copy the IDs from the Console URL, or list them with
qovery project list, qovery environment list and qovery application list.
Create the token
- With the coding agent
- In the Console
In a session signed in as an organization Owner or Admin, ask:The
qovery-policy-token skill finds the IDs, writes a policy like the one above, tests it locally and against the API, then creates the token.Prompt for the agent
The agent runs with the Qovery Agent Skills and the Qovery CLI, in Claude Code, Codex, Cursor or any agent that supports skills. Give it the token through the environment, never in the prompt:policy:<token-id>:<token-name>.
Good to know
- The policy cannot see whether an environment is a preview. It allows deleting any environment of the project except the ones in
protected_environment_ids. Add every new long-lived environment to that list before you create the token. - Qovery can also delete a preview automatically when its pull request is closed. See preview environments. The agent is useful for the previews that stay open but idle.
Related
All agent policy examples
Every use case, from read only to production changes.
API Policy Token (Preview)
How policies are evaluated, the input they see, and the limits.