# Add an e-signature flow with Codex

> Add an e-signature flow with Codex. One task prompt builds a signup clickwrap in your codebase, with tests, the rules in AGENTS.md and an independent record.

Source: https://esigncomply.com/build/codex

Coding agent · Codex

You hand Codex a task and it comes back with a diff. Hand it this one: a signup clickwrap in your own form, built to rules Esign Comply supplies, with every acceptance kept as an independent record.

[Get started](https://esigncomply.com/signup) · [Generate a prompt](https://esigncomply.com/product/prompt-generator)

Free plan: 10 live signatures a month and a full test mode. No card required.

One prompt, from paste to record

1. Put a test key in your server environment · You
2. Paste one prompt into Codex · You
3. Codex wires your form and your server · You
4. Acceptance reported from the user's browser · Esign Comply
5. Sealed record, receipt and timestamp · Esign Comply
6. Server confirms, then creates the account · You

Copy-paste prompt

## The prompt to paste into Codex

Open Codex on your repository and paste this as the task. It builds a signup clickwrap: your Terms of Service and Privacy Notice, accepted with your own checkbox and your own button.

What the prompt tells Codex

- Read `setup.md`, `auth.md` and `llms.txt` before writing anything.
- Create the session on your server with the secret key, and send only the client token to the browser.
- Attach the browser SDK to your own checkbox and button. No widget, no iframe.
- Confirm the record on your server before the account exists.
- Never invent an API method, and stop and ask when something conflicts.

[Generate the prompt for your regions](https://esigncomply.com/product/prompt-generator)

Prompt for Codex

```
Task: add a signup clickwrap to this codebase with Esign Comply. New users accept the Terms of Service and the Privacy Notice with our own checkbox and button, and the account is created only after our server has confirmed the record.

Read first, and follow exactly:
- https://esigncomply.com/setup.md
- https://esigncomply.com/auth.md
- https://esigncomply.com/llms.txt

Changes
1. Server: create the Esign Comply session with the secret key from the environment variable ESIGNCOMPLY_API_KEY. Return only the client token and the document version IDs to the browser.
2. Browser: attach @esigncomply/browser to the signup form that already exists. It observes our unchecked checkbox and our submit button. Call complete() from the user's real click, never from code.
3. Server: confirm the record with the secret key before granting access: status, livemode, signer ID, version IDs.
4. Tests: an unchecked box creates no record, and a made-up record ID is refused.

Constraints
- Use only API methods and packages named in the docs. Never invent one.
- Never write a key to a file that is committed.
- If the docs and the codebase conflict, or a step is unclear, stop and ask me.

Run commands in the sandbox shell and show their output. If the sandbox has no network access, list the commands for me to run. Write these rules to AGENTS.md.
```

5 steps

## How to run it in Codex

Codex is OpenAI's AI coding agent. This is the whole run, from a new Esign Comply account to your first test record.

1. **Create a free account and a test key**

   Sign up, then choose Create test key in the dashboard. The key starts with `esc_test_` and is shown once. No card on the Free plan, and no domain either: test keys work on `localhost`.

2. **Give Codex the key as an environment variable**

   Set `ESIGNCOMPLY_API_KEY` in the environment Codex runs your code in, and in `.env.local` on your own machine. The prompt tells Codex never to write a key to a committed file.

3. **Paste the prompt as the task**

   Codex reads the three docs pages, makes the four changes and writes the rules to `AGENTS.md`. The fourth change is two tests: an unchecked box creates no record, and a made-up record ID is refused.

4. **Run what it lists**

   When Codex lists commands instead of running them, run them in your own terminal: install `esigncomply` and `@esigncomply/browser`, start the app, then `npx esigncomply check --url http://localhost:3000/signup`.

5. **Open the page and tick the box**

   Go to `/signup`, tick the checkbox and click Create account. Your first test record is in the dashboard a moment later.

[Create a free account](https://esigncomply.com/signup) · [Read the quickstart](https://esigncomply.com/docs/quickstart)

The 60-second result

## What you have 60 seconds after Codex finishes

Merge the diff, start the app and sign up once. This is the diff Codex hands back, and the record your first test signup produces.

1. **The server route that creates the session**

   e.g. `app/api/ceremony/route.ts`

   It holds the secret key, pins the current version of each document and hands the browser a short-lived client token.

2. **Your signup form, with the SDK attached**

   e.g. `app/signup/signup-form.tsx`

   Your markup and your styles. The SDK renders nothing: it watches your links, your checkbox and your button, and reports what the user did.

3. **The server confirmation**

   e.g. `app/api/signup/confirm/route.ts`

   The record ID came from the browser, so the server reads the record with the secret key before the account exists.

**Create the session**

```ts
// app/api/ceremony/route.ts
import { esc } from "@/lib/esigncomply";

export async function POST(request: Request) {
  const { signerId, email, attempt } = await request.json();

  const { data: session, error } = await esc.sessions.create(
    {
      profile: "prof_signup_4f1a",
      signer: {
        external_id: signerId,
        email,
        class: "consumer",
        country: "US",
      },
      documents: [
        { document: "doc_8Hq2", version: "current" }, // Terms of Service
        { document: "doc_Pv71", version: "current" }, // Privacy Notice
      ],
      context: {
        url: "http://localhost:3000/signup",
        locale: "en-US",
        purpose: "account_signup",
      },
    },
    { idempotencyKey: `signup-${signerId}-${attempt}` },
  );
  if (error) return Response.json({ error: error.code }, { status: 502 });

  // Save signerId and the pinned version IDs in server-owned state.
  return Response.json({
    clientToken: session.client_token,
    documents: session.documents,
  });
}
```

**Signup form**

```tsx
// app/signup/signup-form.tsx
import { EsignComply } from "@esigncomply/browser";

// After /api/ceremony returns clientToken and documents:
const ceremony = await EsignComply.attach({ clientToken });

await ceremony.presentDocument({
  versionId: documents[0].version_id,
  mode: "hyperlink",
  link: document.querySelector("#tos-link"),
});
await ceremony.presentDocument({
  versionId: documents[1].version_id,
  mode: "hyperlink",
  link: document.querySelector("#privacy-link"),
});

await ceremony.observeAssent({
  region: document.querySelector("#assent"), // notice, links, box, button
  checkbox: document.querySelector("#agree"), // yours, unchecked
  submit: document.querySelector("#create-account"), // your button
});

// Called from the real submit handler, after the user ticked the box.
async function finishSignup() {
  const result = await ceremony.complete();
  // result: { recordId, receipt, verifyUrl, status }
  await fetch("/api/signup/confirm", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ recordId: result.recordId }),
  });
}
```

**Confirm on the server**

```ts
// app/api/signup/confirm/route.ts
import { esc } from "@/lib/esigncomply";

export async function POST(request: Request) {
  const { recordId } = await request.json();
  const expected = await loadCeremonyState(request); // server-owned state

  const { data: record, error } = await esc.records.get(recordId);
  if (error) return Response.json({ confirmed: false }, { status: 409 });

  const versions = record.documents.map((d) => d.version_id).sort();
  const confirmed =
    ["recorded", "timestamped", "anchored"].includes(record.status) &&
    record.livemode === (process.env.VERCEL_ENV === "production") &&
    record.signer.external_id === expected.signerId &&
    versions.join() === [...expected.versionIds].sort().join();

  if (!confirmed) return Response.json({ confirmed: false }, { status: 409 });
  // Only now create the account.
  return Response.json({ confirmed: true });
}
```

The example is a Next.js repository. In another stack, Codex writes the same three parts under that stack's file names.

The record that appears

### One sealed test record, kept by Esign Comply

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

Your first test record opens in the dashboard with what was observed, what was asserted, and the conformance findings. It is sealed like a live record, on a separate test ledger, and its evidence report is watermarked TEST.

[Sign a live demo](https://esigncomply.com/use-cases) · [What a record holds](https://esigncomply.com/product/evidence)

## What Codex gets right with the rules, and wrong without them

A task that says "add terms acceptance" gets a checkbox and a boolean. The prompt turns the rules into constraints Codex can test, and the conformance check measures the page afterwards.

[CR-01](https://esigncomply.com/docs/conformance#cr-01) · block

### Affirmative assent control

Without the rules

The checkbox ships already ticked, or a handler ticks it for the user to save a click.

With the prompt

The box renders unchecked and only a real user event changes it. The SDK records its state at load, and the check reports a pre-checked box or a scripted click at block level.

[CR-02](https://esigncomply.com/docs/conformance#cr-02) · block

### Notice text names every document

Without the rules

One generic line, "By signing up, you agree to our terms", with no document titles and no links.

With the prompt

The notice carries the registered title of every document in the session, each one linked, inside the same container as the checkbox and the button.

[CR-03](https://esigncomply.com/docs/conformance#cr-03) · warn

### Notice names the action control

Without the rules

"By continuing" or "by clicking below", next to a button that says something else.

With the prompt

The notice names the button by its exact label: "By checking the box and clicking Create account, you agree to the Terms of Service." The check flags vague phrases.

[CR-04](https://esigncomply.com/docs/conformance#cr-04) · block

### Notice and control in the same viewport

Without the rules

The agreement line sits in the footer or under a long form, below the fold on a phone.

With the prompt

The notice sits directly above the button in the same container. The SDK records both positions at the signing act, and the check runs your page at 390 by 844.

[CR-08](https://esigncomply.com/docs/conformance#cr-08) · block

### Document links resolve to the registered version

Without the rules

A link to `/terms` that serves whatever is in the repo today, or the legal text pasted into a component.

With the prompt

Every link serves the registered version by its ID, and the record pins that version by SHA-256 hash. Document text is never copied into your code.

Each row is a real conformance rule with its ID and its default level. Esign Comply runs 28 of them over your test records, and every finding names the rule, the measurement and the fix.

[E-signature mistakes AI tools make](https://esigncomply.com/learn/vibe-coded-esignature-mistakes) · [All 28 conformance rules](https://esigncomply.com/docs/conformance)

## Go further with Codex

With the rules in `AGENTS.md`, the next task starts from them. Give Codex a bigger one.

A whole product

### Build your own signing app

Upload a document, email each signer a link to your own application and collect the signatures there. There are 7 build guides, each with the steps and the code.

[Build your own DocuSign](https://esigncomply.com/build/docusign-alternative)

Your stack

### Stack guides

The same integration written out for your framework and your host, with working code for the server, the browser and the confirmation.

[Browse the stack guides](https://esigncomply.com/guides)

Live demos

### Use cases

NDAs, contractor agreements, consent forms, order forms and terms updates. Each page has a live demo you can sign in test mode.

[See the use cases](https://esigncomply.com/use-cases)

Prompt generator

### The exact rules for your regions

Pick your use case, regions, signer types and stack. You get one prompt to paste into Codex, with your own document and profile IDs and the rule packs you selected.

[Generate a prompt](https://esigncomply.com/product/prompt-generator)

### Build guides to follow with Codex

- [Build your own DocuSign](https://esigncomply.com/build/docusign-alternative)
- [Build your own Dropbox Sign](https://esigncomply.com/build/dropbox-sign-alternative)
- [Build your own PandaDoc](https://esigncomply.com/build/pandadoc-alternative)
- [Build your own Adobe Acrobat Sign](https://esigncomply.com/build/adobe-sign-alternative)
- [Build your own signNow](https://esigncomply.com/build/signnow-alternative)
- [Build your own DocSend](https://esigncomply.com/build/docsend-alternative)
- [Build your own clickwrap](https://esigncomply.com/build/clickwrap)
- [All build guides](https://esigncomply.com/build)

### The same prompt for another AI tool

- [Cursor](https://esigncomply.com/build/cursor)
- [Claude Code](https://esigncomply.com/build/claude-code)
- [Windsurf](https://esigncomply.com/build/windsurf)
- [GitHub Copilot](https://esigncomply.com/build/github-copilot)
- [Devin](https://esigncomply.com/build/devin)
- [Lovable](https://esigncomply.com/build/lovable)
- [v0](https://esigncomply.com/build/v0)
- [Bolt](https://esigncomply.com/build/bolt)
- [Replit](https://esigncomply.com/build/replit)
- [ChatGPT](https://esigncomply.com/build/chatgpt)
- [Grok](https://esigncomply.com/build/grok)
- [Grokbot](https://esigncomply.com/build/grokbot)
- [Muse](https://esigncomply.com/build/muse)
- [All AI tools](https://esigncomply.com/build#tools)

## Questions about Codex and e-signatures

### Can Codex build an e-signature flow?

Yes. Give Codex the prompt on this page as a task and it builds a signup clickwrap in your codebase: a server route that creates the session, your existing form with the browser SDK attached, a server confirmation and two tests. Esign Comply supplies the rules and keeps the independent record.

### Where does the API key go when Codex does the work?

In an environment variable named ESIGNCOMPLY_API_KEY, set by you in the environment Codex runs your code in. The prompt tells Codex never to write a key to a committed file, and only server code reads the variable. Use a test key: development never needs a live one.

[Read the quickstart](https://esigncomply.com/docs/quickstart)

### What happens when Codex cannot run a command itself?

It lists the commands and you run them. The prompt says so: run commands in the sandbox shell and show the output, and when the sandbox has no network access, list them for the developer. Paste the output of the conformance check back and Codex fixes the findings.

### Where do the Esign Comply rules live for the next Codex task?

In AGENTS.md. The prompt tells Codex to write them there, and a prompt generated in the Esign Comply dashboard downloads as a marked AGENTS.md section that replaces the earlier one when you generate again.

[Generate a prompt](https://esigncomply.com/product/prompt-generator)

### Is there a generated prompt for Codex?

Yes. Codex is one of the tools in the prompt generator. Pick your use case, your regions, your signer types and your stack, choose Codex, and you get one prompt with your own document and profile IDs and the rules for the packs you selected.

[See the prompt generator](https://esigncomply.com/product/prompt-generator)

## Hand Codex the task. Leave the record to us.

[Get started](https://esigncomply.com/signup) · [Documentation](https://esigncomply.com/docs)

Free plan: 10 live signatures a month and a full test mode. No card required.

Codex is a trademark of its owner. Esign Comply is not affiliated with it.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.
