Secure unsupervised scheduled agent runs (crons) with strict timeouts, read-only tool scopes, atomic work-claim markers, and provider-side idempotency keys on every external side effect.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Cron Idempotency?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/catpilotai-cron-idempotency)
---
name: cron-idempotency
description: Secure unsupervised scheduled agent runs (crons) with strict timeouts, read-only tool scopes, atomic work-claim markers, and provider-side idempotency keys on every external side effect.
license: MIT
metadata:
catpilot:
id: cron-idempotency
version: 1.0.0
severity: high
category: agentic-security
applies_to:
languages:
- any
frameworks:
- any
runtimes:
- claude-code
- cursor
- openclaw
- cline
- aider
- copilot
- codex-cli
control_mappings:
soc2:
- CC7.1
- CC7.2
- A1.2
pci_dss:
- '6.4'
- '10.2'
iso_27001:
- A.12.1.1
- A.12.1.3
nist_csf:
- PR.IP-1
- DE.CM-7
owasp_top_10:
- A04:2021
provenance:
origin: catpilot
incident_derived: true
maintainers:
- team: catpilot-security
references:
- https://stripe.com/docs/api/idempotent_requests
---
## Baseline
**Applies when:** Configuring, writing, or reviewing scheduled agent tasks (cron jobs, heartbeat loops, background workers, or recurring workflows).
**Always:**
- Set an explicit `timeoutSeconds` and token/cost budget on every scheduled agent job, and use deterministic scripts or lightweight models for routine polling.
- Separate read-only monitoring crons from write actions; scheduled jobs must not have `shell`, `write`, `deploy`, or outbound `message` tools unless human digest approval is in the loop.
- Enforce an atomic, durable work-claim and completion marker (`store.claim(item.id, run_id, ttl_seconds)` / `store.mark_done(...)`) before acting on any item so overlapping or retried runs are proven no-ops.
- Pass a deterministic `idempotency_key` to every external side effect (payments, emails, ticket creation, webhook posts, deployments).
- Release claims cleanly on failure (`store.release(item.id)`) only when the side effect did not commit, and log per-run token spend and claimed item IDs.
**Never:**
- Run a scheduled agent with `timeoutSeconds: null`, unrestricted `"tools": "all"`, or permission to edit its own schedule, prompt, or toolset (`cron_edit`).
- Assume wall-clock schedule spacing (`"*/15 * * * *"`) prevents overlapping runs or duplicate side effects.
- Trigger external side effects (charging cards, sending customer emails, deploying) inside a scheduled loop without both a durable work claim and a provider-side idempotency key.
Open the full component before acting: it has the examples, the remediation steps, and the detection patterns.
## Why
Scheduled tasks are unsupervised agent sessions: when a cron job misfires, loops, or overlaps with a slow prior run, no human is watching the terminal. Treating `"every 15 minutes"` as a state boundary rather than a trigger causes duplicate invoices, repeated customer emails, and runaway token bills whenever a run overlaps, restarts, or retries.
## When to apply
Apply this component whenever creating or reviewing cron schedules, background agent workers, heartbeat checks, or queue consumers.
## Rules
### Rule 1 — Bound runtime, tools, and self-modification
Every cron job requires a hard `timeoutSeconds`, an explicit read-only tool allowlist by default, and zero access to schedule/prompt self-modification tools.
### Rule 2 — Atomic work claims before acting
Before acting on any work item, acquire an atomic lease (`claim(item_id, run_id, ttl)`) in durable storage and mark it completed upon success so concurrent or subsequent ticks skip already-claimed work.
### Rule 3 — Idempotency keys on all external side effects
Every external API call that mutates state must carry a deterministic `idempotency_key` derived from the logical unit of work.
## Negative examples
```python
# ❌ Unbounded cron that replays side effects on overlap or retry
def scheduled_run():
for item in fetch_pending_items():
send_invoice(item)
deploy(item)
```
## Remediation
```python
def scheduled_run(store, run_id: str):
for item in fetch_pending_items():
if not store.claim(item.id, run_id=run_id, ttl_seconds=300):
continue
try:
send_invoice(item, idempotency_key=f"invoice:{item.id}")
store.mark_done(item.id, run_id=run_id)
except Exception:
store.release(item.id)
raise
```
## References
- Designing robust and predictable APIs with idempotency — https://stripe.com/docs/api/idempotent_requests