A practical field guide from Automation Ace.
Short answer: AI agents can use Cloudflare Artifacts as a version-controlled workspace: a Worker forks a reviewed baseline into a new repo for each agent session and mints a short-lived, repo-scoped write token; the agent clones it with ordinary Git, commits small changes, attaches prompts and run IDs as git notes, and pushes. A pushed event starts a Workflow that runs tests, then a reviewer with a read-only token inspects the diff and history. Good results are merged or deployed; bad ones are reverted or the repo is deleted.
APIs reflect the Cloudflare Artifacts docs at the time of writing (Artifacts in beta, Workers Paid plan).
Short answer
- Bind Artifacts to a Worker; import or create a baseline repo.
- Fork a repo per session; mint a short-lived write token.
- Agent: clone, commit, add notes, push.
- Push event: run checks and a review.
- Accept, roll back, or delete.
The agent session lifecycle
Agent session lifecycle on Artifacts
1. Session starts Worker forks the reviewed baseline repo -> agent-<session>
2. Token Worker mints a short-lived WRITE token for that repo only
3. Agent works git clone -> edit -> commit (small commits, clear messages)
-> git notes for prompt / run ID -> git push
4. Event cf.artifacts.repo.pushed starts a Workflow
5. Checks Workflow runs lint, tests, build on the pushed commit
6. Review Reviewer (human or agent) gets a READ token; reads diff + log
7. Accept or discard Merge results into the baseline / deploy, or delete the repo
Step 1: Set up the binding and a baseline repo
- Add an
artifactsbinding (for exampleARTIFACTSwith your namespace) to your Wrangler config; runwrangler types. - Create a baseline repo, or import a public HTTPS repo (such as a template from GitHub) as the starting point.
- Develop locally with
wrangler dev; local repos are separate from production and emit lifecycle events (push events are not published locally yet).
Step 2: Fork a repo per session and mint a token
// Worker: create a per-session repo from a baseline and return Git access
export default {
async fetch(request, env) {
// Authenticate and authorize the caller first (omitted here)
const { sessionId } = await request.json();
const baseline = await env.ARTIFACTS.get('starter-repo');
const forked = await baseline.fork(`agent-${sessionId}`, {
description: `Agent session ${sessionId}`,
defaultBranchOnly: true,
});
using repo = await env.ARTIFACTS.get(`agent-${sessionId}`);
const token = await repo.createToken('write', 3600); // 1 hour, this repo only
return Response.json({ remote: forked.remote, token: token.plaintext,
expiresAt: token.expiresAt });
},
};
Authorize the caller before returning tokens. Binding methods: Workers binding reference.
Step 3: Let the agent work with plain Git
# Inside the agent's sandbox or container
git -c http.extraHeader="Authorization: Bearer $ARTIFACTS_TOKEN" clone "$ARTIFACTS_REMOTE" work
cd work
# ... agent edits files ...
git add -A
git commit -m "Add retry with backoff to the invoice sync"
git notes add -m "run_id=run_8812 prompt_sha=4f2a model_step=plan-2" # harness metadata
git -c http.extraHeader="Authorization: Bearer $ARTIFACTS_TOKEN" push origin main
git -c http.extraHeader="Authorization: Bearer $ARTIFACTS_TOKEN" push origin refs/notes/*
- Pass the token as an
http.extraHeaderso it stays out of Git config and logs. - Ask the agent for small, focused commits with messages that explain why.
- Running agents in Cloudflare Sandbox containers? Cloudflare documents passing an authenticated remote as an environment variable to the sandbox.
Triggering coding agents: triggering Claude Code agents via API.
Step 4: Trigger checks and reviews on push
- Add a
cf.artifacts.repo.pushedtrigger that starts a Workflow; filter by namespace and optionally repo name. - The Workflow checks out the pushed commit and runs install, lint, tests, and build.
- Start a review agent with a read token, or notify a person with the diff link.
Multistep patterns: Cloudflare Workflows and durable workflows explained.
Step 5: Read history, review, and roll back
# Read history and files without cloning (REST API, Cloudflare API token)
curl "$ARTIFACTS_BASE_URL/repos/agent-123/log?ref=main&limit=10" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
curl "$ARTIFACTS_BASE_URL/repos/agent-123/file?ref=main&path=src/sync.ts" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
// Or from a Worker
using repo = await env.ARTIFACTS.get('agent-123');
const file = await repo.readFile({ ref: 'main', path: 'src/sync.ts' }); // Blob or null
- Review the log and diffs against the baseline; read git notes to see which prompt or run produced each commit.
- Roll back with
git revert(keeps history) rather than rewriting history.
Step 6: Accept results and clean up
- Merge accepted changes into the baseline or deploy (Workers Builds can deploy a connected repo on push).
- Delete finished or abandoned session repos; storage is billed until you delete them.
- Revoke tokens you no longer need.
Practices that keep agent repos safe
| Practice | Why |
|---|---|
| One repo per agent session | Isolated history, failures, and cleanup; no shared hot spot |
| Fork from a reviewed baseline | Consistent starting point; easy diffs back to the baseline |
| Unique names (agent + session + purpose) | Names are unique per namespace; avoids collisions |
| Short-lived write token for the agent only | Limits damage if a token leaks |
| Read tokens for reviewers and indexers | They can't change anything |
| Small commits with clear messages | Reviewable diffs and precise rollbacks |
| Git notes for prompts and run IDs | Traceability without polluting files |
| Delete or archive finished repos | Storage is billed until you delete |
Approvals for agent actions: permissions, approvals, and audit trails. Versioning prompts: versioning and testing AI prompts. Where to host code instead: Cloudflare Artifacts vs GitHub.
Frequently asked questions
How do AI agents use Cloudflare Artifacts?
A Worker creates or forks a repo for each agent session and mints a short-lived repo-scoped token. The agent clones, commits, and pushes with normal Git, push events trigger checks and reviews, and results are merged, rolled back, or deleted.
Should each AI agent get its own repo?
Yes. Cloudflare recommends one repo per agent, session, or unit of work so changes, failures, and cleanup stay separate. Use unique names that include the agent and session.
How do I give an agent access to an Artifacts repo?
Mint a repo-scoped token from the Workers binding or REST API, with write scope and a short TTL for the agent that pushes, and read scope for reviewers. Pass it as an HTTP header to Git.
How do I track which prompt produced a commit?
Attach prompts, run IDs, and other harness metadata with git notes, which Cloudflare suggests because notes don’t change the commit or working tree.
Can I run tests automatically when an agent pushes?
Yes. Add a cf.artifacts.repo.pushed trigger that starts a Workflow to check out the commit and run lint, tests, and builds, and optionally deploy.
Disclaimer: Cloudflare Artifacts was in beta at the time of writing; APIs, limits, pricing, and event types can change, so test with your own workloads before relying on them in production; details reflect public documentation and coverage at the time of writing, so confirm current details with each provider before building. Automation Ace is not affiliated with Cloudflare or GitHub. This article may include links to apps, products, or services; some links may be affiliate links, which means Automation Ace may earn a commission at no extra cost to you.