Guides › Guides
Use Dispra with AI agents
6 min · 7 steps · Languages: dcloud
Claude Code, Codex, Cursor and other coding agents can deploy your services, read the logs of a failed deployment, fix the code and deploy again. They do it through dcloud, which is built for them: JSON output, exit codes that say when a person must act, and no prompts that would hang an agent.
1. Install the CLI where the agent runs
On your own machine, install dcloud once and every agent you run there can use it (see Install the CLI). In a cloud sandbox, such as Codex cloud, Claude Code on the web or a CI runner, add the install script to the environment's setup.
Install (Homebrew)
brew install prethmhq/tap/dcloud
Install (Install script)
curl -fsSL https://dispralabs.com/downloads/dcloud-cli.sh | sh
Dispra Cloud CLI
brew install prethmhq/tap/dcloud
2. Sign in
On your own machine, sign in once with dcloud login in your terminal, and agents you run there use your sign-in, in the projects you can reach. An agent that finds you signed out runs dcloud login --json itself: it answers exit code 2 with a link and a code, which the agent shows you. Open the link, allow the device, and tell the agent, which runs dcloud login --json again to finish.
In a sandbox without a browser, such as Codex cloud, Claude Code on the web or CI, nobody can sign in. Make a project developer key and set it as the sandbox's DCLOUD_TOKEN secret. Give it the least access that works: read for an agent that only looks into failures, deploy for one that deploys, and full only when it must change variables, domains or dispra.yaml. Limit it to a non-production environment such as staging, so a mistake can't reach production. Sign in from CI and sandboxes shows how.
Dispra Cloud CLI
# your machine
dcloud login
# a sandbox or CI: a secret, never in the repository
export DCLOUD_TOKEN=dsp_live_...
dcloud link --project prj_01jdk3m9x2v7c4q8w5n6b1t0ra --env staging
3. Write the instructions into your repository
dcloud agents writes what an agent needs to know into the repository: how to call dcloud, how to read a refusal, the deploy loop, variables, domains, dispra.yaml, what never to run on production without asking, and the project and environment the folder is linked to.
It writes a block to AGENTS.md, the file Codex, Cursor and most agents read. When the repository has a CLAUDE.md, or with --claude, it adds @AGENTS.md to it, so Claude Code reads the same block. The block sits between <!-- dcloud:start --> and <!-- dcloud:end -->: run dcloud agents again after linking another environment or upgrading, and it replaces the block and leaves the rest of the file alone. Commit the files.
dcloud agents --print writes the block to stdout instead, to paste it elsewhere.
Dispra Cloud CLI
dcloud link
dcloud agents
# /home/me/shop/AGENTS.md: created
# /home/me/shop/CLAUDE.md: updated
git add AGENTS.md CLAUDE.md && git commit -m "Dispra Cloud instructions for agents"
4. Add the Claude Code plugin
With the dcloud plugin, Claude Code knows the Dispra workflow in every project, without a word in your CLAUDE.md: how to install dcloud, how to sign in, the deploy loop, logs, variables, domains and the safety rules. Its skill loads by itself when you ask Claude Code to deploy, read logs or set variables. It also adds two commands: /dcloud:deploy [service] deploys and fixes until the service is live, and /dcloud:logs [service] [search text] reads and explains a service's recent logs.
In Claude Code, add the marketplace, then install the plugin. Update it later with /plugin marketplace update dispra.
Dispra Cloud CLI
/plugin marketplace add PrethmHQ/dispra-cli
/plugin install dcloud@dispra
# or from a terminal
claude plugin marketplace add PrethmHQ/dispra-cli
claude plugin install dcloud@dispra
5. The agent contract
dcloud behaves the same for every agent:
--jsonprints one JSON object per line on stdout; text for people goes to stderr. It works before or after the command:dcloud --json statusordcloud status --json.- Exit codes:
0done,1an error,2a person must act. - Refusals are one JSON line:
{"status", "code", "message", "action", "action_url"}.statusisrefused(exit 1), oraction_requiredorlogin_required(exit 2). On exit 2 the agent shows the person the message and theaction_url, and stops. confirmation_required: a command that changes something a person should approve (stopping a service, deleting variables, applyingdispra.yaml, removing a domain) asks first. An agent can't answer, sodcloudrefuses with exit 2 and the agent asks you;--yesgoes ahead.- Agent mode:
dcloudnever prompts and never waits for input whenCLAUDECODE=1is set (Claude Code sets it), whenDCLOUD_AGENT=1is set, or when stdin isn't a terminal.
Dispra Cloud CLI
dcloud stop api --json
# {"action":"confirm","action_url":"","code":"confirmation_required",
# "message":"Stop api in production? It stays stopped until you start it. Run again with --yes to go ahead.",
# "status":"action_required"}
echo $?
# 2
6. The deploy loop
This is the loop the instructions and the plugin teach:
dcloud status --json: the services of the environment and their latest deployments.dcloud deploy <service> --wait --json: deploy, then wait until it isliveor failed. A service built from GitHub deploys the latest commit of its branch, so the agent commits and pushes first. A service deployed from a folder (source: {path: .}indispra.yaml) uploads the folder.- If it failed:
dcloud logs <service> --build <dep_...> --jsonreads the build log, anddcloud logs <service> --no-follow -n 200 --jsonthe running service's log. - Fix the cause, and deploy again.
Without --no-follow, --page or --build, dcloud logs follows the live log and never returns, so agents always add one of them.
Dispra Cloud CLI
dcloud deploy api --wait --json
# its last line:
# {"dep":"dep_01jdk4p7q9w1e3r5t7y9u1i3ob","error_code":"...","service":"api","state":"failed","status":"failed"}
dcloud logs api --build dep_01jdk4p7q9w1e3r5t7y9u1i3ob --json
dcloud logs api --no-follow -n 200 --json
7. Keep it safe
- Let agents work in a non-production environment (
dcloud env create staging --from production), and keep production to a person, or to a key limited to staging. - Use the least access that works, and one key per sandbox or pipeline, so you can revoke one without breaking the others.
- Never paste a key into a chat, a prompt or the repository: set it as the sandbox's secret.
dcloud varslists names, never values. Tell agents not to read or print secret values (dcloud vars pullwrites them to a file).- Destructive commands, such as
rollback,stop,vars unset,domain remove,apply --pruneor deleting anything, are for a person to approve. The instructions tell agents so, anddcloudasks for confirmation where it can. - Review what the agent changed in Activity on the dashboard: every change made with a key is recorded with the key's name.
Next steps
Next: Sign in from CI and sandboxes to make the key, and Config as code: dispra.yaml to let agents change an environment through a reviewed file.