# Deliver Remote Mac Agent Results Through an API

Canonical: https://figment.so/blog/mac-agent-artifact-delivery

Deliver each artifact with an idempotency key, a SHA256 checksum and a signed receipt, so retries are safe and both sides can prove the delivery. A Figment Intel Mac VM ($25 a month) runs it.

Deliver a Mac agent's results with three properties: an **idempotency key** so retries are safe, a **SHA256 checksum** so the receiver can verify integrity, and a **signed receipt** so both sides agree the delivery happened. Network blips, transient 5xx responses and partial uploads can otherwise leave the downstream API with stale data or nothing. This page gives the receipt schema, a short reference script and an acceptance worksheet, so you can prove the behaviour on your own endpoint before the agent runs unattended.

## Which Figment Mac plan delivers artifacts to an API?

The [Intel Mac VM](/mac-hosting#intel-vm) ($25 a month, $2 a day, $0.15 an hour) is enough for most delivery jobs: reports, JSON, Intel-compatible binaries and zipped bundles. It has 4 shared vCPUs, 4GB of RAM and an 80GB SSD, and runs macOS Sequoia. Outbound HTTPS works normally, so the agent can POST to an API, an S3-compatible store or an artifact registry from a terminal over SSH. Xcode 26.0 to 26.3 runs on Sequoia and can build and sign many iOS and universal macOS targets from this VM.

The Intel VM cannot run arm64-only binaries, visionOS or Xcode 26.4 or later, which needs macOS Tahoe 26.2 or later. Apple's [porting notes](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon.md) cover Xcode on Intel Macs. Choose another plan for those cases:

- **[Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm)** ($39 a month, $6 a day): arm64 execution or newer Xcode. It has 4 shared vCPUs and 4GB of RAM.
- **[Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro)** ($349 a month, or $299 a month on a 12-month term): concurrent signing jobs or large artifacts on a whole Mac (M4 Pro, 48GB RAM, 512GB SSD).

Figment runs the Mac and network layer. Your delivery script, keys, CI and the receiving API are yours.

## What should the agent and the API promise each other?

Agree this contract before you write any script:

| Requirement | Implementation |
|---|---|
| Exactly-once delivery | Idempotency key tied to `run_id` + artifact name |
| Integrity verification | SHA256 (hex) sent as a custom header; server re-checks before accepting |
| Retry safety | Same idempotency key returns the same result on re-POST |
| Delivery evidence | HMAC-signed receipt stored locally and acknowledged by server |
| Failure visibility | Non-2xx responses logged with body; attempts counted |

If your target is S3-compatible, Amazon's [CompleteMultipartUpload reference](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html) documents both halves of this contract. The `x-amz-checksum-sha256` header makes the server verify an integrity hash. S3 expects the digest **Base64-encoded**, not the hex form that `shasum -a 256` prints, so convert with `openssl dgst -binary -sha256 <file> | openssl base64` before sending. `If-None-Match: *` on the completion request returns `412 Precondition Failed` when the key already exists. If your API is custom, pick your own header names but keep the same shape: one header carries the idempotency key, one carries the integrity hash, and the server documents how it responds when the same key is re-POSTed.

## What does the signed receipt look like?

It is a JSON record written only after a confirmed 2xx or a server-signalled duplicate (for example 409). The receipt records the actual HTTP status, so the audit trail stays honest, and a separate `outcome` field explains how the agent treated it.

```json
{
  "schema": "delivery-receipt/v1",
  "run_id": "2026-11-10T14-32-01Z-a3f8b2",
  "artifact": {
    "name": "analysis-report.json",
    "bytes": 28441,
    "sha256_hex": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
  },
  "delivery": {
    "endpoint": "https://api.example.com/results",
    "idempotency_key": "run-a3f8b2-analysis-report.json",
    "attempt": 1,
    "delivered_at": "2026-11-10T14:33:12Z",
    "http_status": 201,
    "outcome": "accepted",
    "delivery_id": "srv-delivery-77f3c1"
  },
  "receipt_hmac": "sha256=<hmac of the canonical payload with the receipt-signing key>"
}
```

`outcome` is `accepted` (2xx) or `duplicate` (the server indicates the idempotency key was already recorded). `receipt_hmac` is an HMAC-SHA256 over the compact JSON of the other fields, using a key held in your secret manager. Any downstream service with the same key can confirm the receipt was issued by your agent and was not altered.

## What does the reference delivery script look like?

This is an untested reference example. It is short so you can read it in one sitting. Plug in your endpoint, your header names and your duplicate-detection semantics, then walk the acceptance worksheet below against a disposable endpoint before using it on production data.

```bash
#!/usr/bin/env bash
# Reference delivery script. NOT verified end-to-end; run the
# acceptance worksheet below before using it for real artifacts.
set -euo pipefail

ARTIFACT="${1:?Usage: $0 <artifact-path> <endpoint>}"
ENDPOINT="${2:?Usage: $0 <artifact-path> <endpoint>}"
: "${API_TOKEN:?API_TOKEN required (read from the CI secret manager)}"
: "${RECEIPT_SIGNING_KEY:?RECEIPT_SIGNING_KEY required}"
: "${RUN_ID:?RUN_ID required; the retrying step must reuse the original value}"

ARTIFACT_NAME=$(basename "${ARTIFACT}")
IDEMPOTENCY_KEY="${RUN_ID}-${ARTIFACT_NAME}"
ARTIFACT_SHA_HEX=$(shasum -a 256 "${ARTIFACT}" | awk '{print $1}')
ARTIFACT_BYTES=$(stat -f "%z" "${ARTIFACT}")

umask 077
RESPONSE_FILE=$(mktemp -t deliver.XXXXXXXX)
trap 'rm -f "${RESPONSE_FILE}"' EXIT

ATTEMPT=0; MAX_ATTEMPTS=5; BACKOFF=2; HTTP_STATUS=000; OUTCOME=failed
while (( ATTEMPT < MAX_ATTEMPTS )); do
  ATTEMPT=$(( ATTEMPT + 1 )); : > "${RESPONSE_FILE}"
  HTTP_STATUS=$(curl --silent --show-error --max-time 60 \
    --write-out "%{http_code}" --output "${RESPONSE_FILE}" \
    --header "Authorization: Bearer ${API_TOKEN}" \
    --header "Content-Type: application/octet-stream" \
    --header "X-Idempotency-Key: ${IDEMPOTENCY_KEY}" \
    --header "X-Content-SHA256-Hex: ${ARTIFACT_SHA_HEX}" \
    --data-binary "@${ARTIFACT}" \
    "${ENDPOINT}") || HTTP_STATUS=000
  case "${HTTP_STATUS}" in
    2*)   OUTCOME=accepted;  break ;;
    409)  OUTCOME=duplicate; break ;;  # server says this key was already recorded
    *)    echo "attempt ${ATTEMPT} HTTP ${HTTP_STATUS}: $(cat "${RESPONSE_FILE}")" >&2
          (( ATTEMPT < MAX_ATTEMPTS )) && sleep "${BACKOFF}" && BACKOFF=$(( BACKOFF * 2 )) ;;
  esac
done
[[ "${OUTCOME}" == failed ]] && { echo "ERROR: all ${MAX_ATTEMPTS} attempts failed" >&2; exit 1; }

DELIVERY_ID=$(jq -r '.delivery_id // empty' "${RESPONSE_FILE}" 2>/dev/null || true)
PAYLOAD=$(jq -cn \
  --arg run_id "$RUN_ID" --arg name "$ARTIFACT_NAME" --argjson bytes "$ARTIFACT_BYTES" \
  --arg sha "$ARTIFACT_SHA_HEX" --arg endpoint "$ENDPOINT" --arg key "$IDEMPOTENCY_KEY" \
  --argjson attempt "$ATTEMPT" --arg at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
  --argjson status "$HTTP_STATUS" --arg outcome "$OUTCOME" --arg did "$DELIVERY_ID" \
  '{schema:"delivery-receipt/v1",run_id:$run_id,
    artifact:{name:$name,bytes:$bytes,sha256_hex:$sha},
    delivery:{endpoint:$endpoint,idempotency_key:$key,attempt:$attempt,
              delivered_at:$at,http_status:$status,outcome:$outcome,delivery_id:$did}}')
HMAC=$(printf '%s' "${PAYLOAD}" \
  | openssl dgst -sha256 -mac HMAC -macopt "key:${RECEIPT_SIGNING_KEY}" \
  | awk '{print "sha256=" $NF}')

OUT_DIR="${HOME}/receipts/$(date -u +%Y-%m-%d)"
mkdir -p "${OUT_DIR}"
OUT_FILE="${OUT_DIR}/delivery-${RUN_ID}-${ARTIFACT_NAME}.json"
printf '%s' "${PAYLOAD}" | jq -c --arg h "$HMAC" '. + {receipt_hmac:$h}' > "${OUT_FILE}"
echo "receipt: ${OUT_FILE}"
```

Check these properties before you adopt it:

- `set -euo pipefail` with a single EXIT trap cleans the temp file on every exit path.
- `umask 077` is set before any sensitive write, so the receipt is written with mode 0600.
- The retry loop uses exponential backoff with a bounded attempt count.
- A 409 is captured as `duplicate`, and the receipt records the actual 409 instead of rewriting it to 200.
- `awk '{print $NF}'` reads the HMAC hex whether OpenSSL emits `(stdin)= ...` or `HMAC-SHA256(stdin)= ...`.
- `API_TOKEN` and `RECEIPT_SIGNING_KEY` come from your secret manager, not from positional arguments or an environment dump written to disk, because a dump can leak unrelated secrets that share the environment.

## How do I prove the script works before production?

Run these seven checks against a disposable endpoint you control, and record each as pass or fail in a run log. A single failure means the script is not yet acceptable for production on your endpoint.

1. **Shape check.** Deliver a 1 KB file with a valid token. The receipt must parse with `jq .`, `delivery.outcome` must be `accepted`, and `delivery.http_status` must be 2xx.
2. **Hash integrity.** Modify one byte of the artifact after the first upload. Deliver again with a new `RUN_ID`. The server's recorded SHA256 must differ from the first receipt's `sha256_hex`.
3. **Idempotent retry.** Re-run the script with the **same** `RUN_ID` and the same artifact. Expected: `outcome:duplicate`, HTTP 409 (or your API's documented duplicate signal), and the server returns the original `delivery_id` from run 1.
4. **Backoff under failure.** Point the script at a URL that returns 503. Confirm it attempts exactly 5 times with sleeps of 2, 4, 8, 16 seconds between attempts, then exits non-zero with no receipt file written.
5. **Auth revocation.** Deliver with `API_TOKEN=invalid`. Expected: 401 or 403 on attempt 1. If your API documents that auth failures are non-transient, add a `401|403) break` arm to the `case` so you do not waste the retry budget. Confirm a non-zero exit and no receipt file.
6. **Receipt tamper detection.** Edit a byte inside the stored receipt JSON. Recompute the HMAC over `jq -c 'del(.receipt_hmac)' receipt.json` and compare it to the stored `receipt_hmac`. They must differ.
7. **Launchd scheduling.** If you schedule the agent with a user-agent plist per Apple's [launchd job documentation](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html), load secrets from your secret manager or Keychain and never inline literals into the plist. Confirm the job is loaded with `launchctl print gui/$(id -u)/<label>`.

If check 3 returns a fresh `delivery_id` on the second run, your server is not enforcing the idempotency key. Fix that at the server before relying on retries. If check 6 fails (a tampered receipt still verifies), your HMAC key is empty or the canonicalisation is wrong. Do not deploy until it passes.

## What does a year of delivery hosting cost?

A delivery-only agent rarely needs Apple silicon, so the closest comparison is Figment's Intel Mac VM. If you also need arm64 execution, compare the Apple Silicon Mac VM, which is a virtual machine with shared vCPUs, and remember that the CloudMac rows below are whole Mac mini M4 machines.

| Option | Headline | 12 months paid | Hardware class |
|---|---|---|---|
| Figment Intel Mac VM | $25/mo | 12 × $25 = **$300** | Intel VM, 4 shared vCPUs, 4GB, 80GB |
| Figment Apple Silicon Mac VM | $39/mo | 12 × $39 = **$468** | 4 shared vCPUs, 4GB, 65GB |
| Figment Dedicated M4 Pro 48 GB | $349/mo | **$3,228** paid up front (12 × $299 = $3,588 billed monthly) | Whole Mac, M4 Pro, 48GB, 512GB |
| [CloudMac M4/16GB/256GB monthly](https://cloudmac.org/pricing) | $99.99/mo | 12 × $99.99 = **$1,199.88** | M4, 16 GB, 256 GB |
| CloudMac M4/16GB/256GB annual | $999/yr | **$999** (effective $83.25/mo) | M4, 16 GB, 256 GB |

For the pure delivery job in this guide, the Intel VM is **$699** less over a year than CloudMac's annual plan ($999 − $300 = $699). If the workload needs arm64 execution, Figment's Apple Silicon VM is **$531** less than CloudMac's annual plan ($999 − $468 = $531), but it is a shared VM with 4GB of memory, while CloudMac's listing is a whole M4 with 16GB. Figment's Dedicated M4 Pro costs more than either CloudMac option and is a larger machine (M4 Pro, 48GB, 512GB). CloudMac's 512 GB and 1 TB M4 rows are marked "Fully reserved" on the page we fetched, and the 256 GB row is "Reserve now."

## How do I start, or migrate an existing delivery script?

Switch to an idempotency-key header and an integrity-hash header (whatever names your API documents), add the retry loop with 409 treated as a duplicate, write the HMAC-signed receipt, and walk the seven-step worksheet on a disposable endpoint. Keep the real signing key and API token in your secret manager, keep the script in source control, and keep receipts on the machine that produced them and in your downstream audit store.

When you are ready to host the agent, the Intel Mac VM is the direct answer for HTTPS-delivery-only jobs. Move to an Apple silicon plan when you need arm64 execution. Compare the [Mac hosting plans](/mac-hosting).

---

**Related guides:** [Workspace isolation on a hosted Mac](/blog/mac-agent-workspace-isolation) · [Job checkpoints on a hosted Mac](/blog/mac-agent-job-checkpoints) · [GitHub Actions self-hosted runner on Mac](/blog/mac-github-actions-self-hosted-runner)
