Docs/Emulators
#

Emulators

Stand-ins for sign-in, email, payments, Jira, Slack, GitHub, AWS and object storage that run inside every sandbox.

Emulate my app's outside services

Each sandbox (a live copy of your app, also called a test environment) runs its own stand-ins for the outside services your app uses. Your app keeps its normal SDKs and URLs. Nothing real gets sent, and a test can check what your app sent.

These services have emulators.

AreaEmulated
Sign-inGoogle, any OpenID Connect provider (Auth0, Okta, Keycloak, Clerk), Amazon Cognito
EmailAmazon SES, SendGrid, Resend, Postmark, Mailgun, Mailosaur
PaymentsStripe billing (customers, Checkout, subscriptions, billing portal)
Work toolsJira, Slack, GitHub
AWSSecrets Manager, KMS, Parameter Store
FilesS3 and Google Cloud Storage
Anything elseA small script in your repo

Add an emulator

  1. List what your app calls. cofactor sandbox guide feasibility gives each dependency one verdict: built in, emulated, installable as a service, real, or unsupported.

  2. Declare the emulator under emulation: in cofactor.sandbox.yaml. For AWS, give each service its own section, such as emulation.aws.cognito. The emulator answers only the services you declare, and it doesn't intercept calls to the others.

    yaml
    emulation:
      email: {}
      jira: { tenant: acme }
    

    The plugin ids are email, google-oauth, oidc, aws, stripe, github, jira, slack and scripted. Files use object_storage instead.

  3. Set reload_on_prepare: true on every service that calls an emulated provider. Without it, the service's calls fail TLS.

  4. Add personas if you emulate sign-in. Each persona becomes an account at the provider, so sign-in emulators need at least one. See Seed data and logins.

  5. Claim a sandbox and trigger a send in your app. Then read what the emulator captured.

    bash
    cofactor sandbox claim --application "Acme App" --wait
    cofactor sandbox run <sandbox id> email.sent-emails
    
    The captured emails list after an invitation, with subject and recipient

Check it worked

bash
cofactor sandbox envs --application "Acme App"

envs lists each declared plugin's operations. A test send shows up in email.sent-emails. The aws operations (aws.secrets, aws.cognito-pools and aws.parameters) show seeded state and read counts, not captured calls. A signed-out test completes your real sign-in button and callback as a persona. On an emulated domain, a call the emulator doesn't implement returns 501 and never reaches the real provider. A scripted emulator answers every call to its domains itself.

Go deeper

  • cofactor sandbox emulators <emulator id> prints one emulator's domains, config keys and operations. cofactor sandbox guide emulation covers every option.
  • Object storage
  • Receiving email covers test inboxes and reading the sign-in codes and links your app emails to a test user.
Advanced

Provider details, scripted emulators and common errors.

Google. Declare google-oauth: {}, set your client id, secret and redirect URI through env:, and add personas. Cofactor's browser shows an account chooser listing each persona. It covers server-started redirect flows. One Tap, FedCM and popup sign-ins are unsupported.

OpenID Connect. Declare oidc: {} and point your app's issuer setting at the sandbox's public emulation address, with issuer_url: { port: emulation }.

Cognito. Declare emulation.aws.cognito with your real pool id and client id. Personas become the pool's users, and the hosted UI works.

Email. Mail through SES in an unlisted region, an unlisted provider host or SMTP leaves the sandbox. Leave SMTP unconfigured, or run Mailpit as a service.

Stripe and object storage. Run cofactor sandbox emulators stripe, and see object storage.

Your own emulator. Add emulation.scripted.<name> with run, domains, port and env. Every field is required, so use env: {} if you have none. The script serves plain HTTP on 127.0.0.1 at that port and answers GET / with a status below 400.

Errors. TLS errors mean the service lacks reload_on_prepare: true. An emulator that never becomes healthy in a pushed image needs openssl. No captured mail means it left through SMTP or an unintercepted host.