This example generates a Worker project in a Workspace, publishes it to Cloudflare Artifacts, and returns a clone-ready URL.
Run it with Wrangler:
npm run dev --workspace @example/computer-artifactsOr deploy it and test against the remote runtime:
npx wrangler deploy --config examples/artifacts/wrangler.jsoncCreate a generated Worker by posting a Worker-safe name:
curl -X POST http://localhost:8787/create \
-H 'content-type: application/json' \
-d '{"name":"my-generated-worker"}'Against a deployed Worker:
curl -X POST https://<worker-subdomain>.workers.dev/create \
-H 'content-type: application/json' \
-d '{"name":"my-generated-worker"}'The Worker endpoint owns the orchestration. The durable object stays minimal: it owns the Workspace, exposes getWorkspace(), and bridges the host Artifacts binding into the worker-backend shell's artifacts command.
POST /create does the following through ws.runtime.exec(...):
- clones
https://github.com/cloudflare/computerinto/workspace/<name>-source; - copies
/workspace/<name>-source/examples/worker-shellto/workspace/<name>; - rewrites the copied Worker name with
sed; - initializes and commits the generated project with the shell
gitcommand; - runs
artifacts create <name> --remote origin --force— one command that creates the session-scoped Artifact repo, mints a write token, and registers the credentialed remote asorigin; - pushes
HEAD:maintoorigin; - runs
artifacts share <name> --scope read— one command that mints a short-lived read token and returns a single clone-ready URL — and returns a clone command built from it.
A successful response looks like:
{
"name": "my-generated-worker",
"artifactRepo": "my-generated-worker",
"remote": "https://<account>.artifacts.cloudflare.net/git/computer-artifacts-example/<repo>.git",
"branch": "main",
"projectDir": "/workspace/my-generated-worker",
"shareLink": "https://x:<token>@<account>.artifacts.cloudflare.net/git/computer-artifacts-example/<repo>.git",
"cloneCommand": "git clone 'https://x:<token>@<account>.artifacts.cloudflare.net/git/computer-artifacts-example/<repo>.git' my-generated-worker"
}Treat shareLink and cloneCommand as secrets. The embedded read token expires after 24 hours.
The Artifacts binding is configured with remote: true, so local wrangler dev talks to the remote Artifacts service.