Skip to main content

Salesforce sandbox security: production data, outside production controls

A Full sandbox is a copy of production. It holds the same customer records, the same personal data and often the same integration settings, but it rarely gets the same care. More people have access, admin rights are handed out for testing, monitoring is thinner and nobody thinks of it when the auditor asks where personal data lives. For a regulator, a copy of customer data in a sandbox is still customer data.

This post covers what each sandbox type actually contains, how to mask data, who should have access, what to do on every refresh and how to stop sandboxes from talking to production systems.

What each sandbox type contains

Every sandbox copies production's metadata and configuration. The difference is data:

Type Data copied Refresh interval
Developer Metadata only 1 day
Developer Pro Metadata only, more storage 1 day
Partial Copy Metadata plus a sample of records chosen by a sandbox template 5 days
Full Metadata plus all data (a template can narrow it) 29 days

Salesforce's sandbox overview describes the types. Two details matter for security:

  • Users are copied into every sandbox type, including Developer. A Developer sandbox holds no records, but it holds your user list and your configuration, including what the org trusts.
  • A Partial Copy is not "test data". The template picks objects, and the sample is real records from production. If the template includes Contact or Case, the sandbox holds real personal data.

Masking data before people use it

If a Full or Partial Copy sandbox holds personal data, mask it before anyone outside the production access list gets in. The main options:

  • Salesforce Data Mask, a managed package installed in production that runs in sandboxes. It can replace values with random characters, replace them with realistic but unrelated values, or delete them. Salesforce introduced it to secure sandbox data. Masking is one way: the original values are gone from that sandbox.
  • A post-copy Apex class. A class that implements the SandboxPostCopy interface runs automatically after a sandbox is created or refreshed. It is the right place for org-specific clean-up such as rewriting contact emails and disabling jobs.
  • A sandbox template that leaves sensitive objects out of a Partial Copy entirely.

Whatever you choose, decide per field. A masking plan that lists objects but not fields usually misses long text fields: descriptions, comments and notes often contain the most sensitive details of all.

A post-copy class is short and testable:

// Runs after every sandbox create or refresh
global class SandboxPrep implements SandboxPostCopy {
    global void runApexClass(SandboxContext context) {
        List<Contact> contacts = [SELECT Id FROM Contact WHERE Email != null LIMIT 10000];
        for (Contact c : contacts) {
            c.Email = c.Id + '@example.invalid';
            c.Phone = null;
        }
        update contacts;
        // Large orgs: move this into a batch job started from here.
    }
}

Who has access

By default, a sandbox copies every production user, and those users can log in with the sandbox username (the production username plus the sandbox name) and their production password from the time of the copy. That means everyone who can see customer data in production can see it in a Full sandbox too, and often more, because sandbox profiles drift toward "System Administrator for testing".

Controls worth using:

  • Selective sandbox access. When you create or refresh a sandbox, you can choose a public group. Users outside the group are frozen in the sandbox, so only the people who need it can log in.
  • No admin creep. Track who was granted admin in each sandbox and remove it after the test it was for.
  • The same identity controls as production. MFA, SSO and session settings should come across in the copy; check they have not been relaxed afterwards.
  • External users. Experience Cloud users and guest settings are copied too. A sandbox site with a public URL can expose copied data to anyone who finds it.

Email and notifications

Salesforce appends .invalid to user email addresses in a new or refreshed sandbox so it does not email your staff by accident. It does not change contacts, leads or other records, so a test workflow can still email real customers. New and refreshed sandboxes default email deliverability to system email only; if a tester switches it to all email, real contact addresses become live recipients. Mask or rewrite contact emails in the post-copy step before anyone enables all email.

Integrations that still point at production

A sandbox copies Named Credentials, connected apps, remote site settings and outbound message endpoints. Unless you change them, a test callout from a sandbox goes to the same endpoint production uses. That can mean test orders sent to a real fulfilment system, test refunds sent to a real payment provider, or production API credentials stored in an environment with a wider audience.

On every refresh:

  1. Repoint Named Credentials to the partner's test endpoints, and replace production secrets with test ones. (Secrets belong in External Credential principals, which you set per org, so a refresh is the moment to set test values.)
  2. Review connected apps and integration users. An external system authenticated to production should not silently be given a sandbox login.
  3. Check outbound messages and scheduled jobs that call out.
  4. Rotate any secret that was exposed to the sandbox audience.

Refresh hygiene

An old sandbox is a security problem of its own. It holds a snapshot of data that has since been deleted in production (a deletion request you honoured in production may not have reached the sandbox), and its configuration no longer matches what production enforces. Refresh on a schedule, delete sandboxes nobody uses, and run the same masking and repointing steps on every refresh, ideally from the post-copy class so nobody forgets.

How Vulkro for Salesforce helps

Three commands map to this work:

# Stale refreshes and sandboxes near expiry (run against the Dev Hub)
vulkro-sf org sandbox-refresh-lag --target-org my-devhub

# A per-field masking proposal from your field metadata
vulkro-sf masking-rules . > masking-rules.json

# Configuration drift between a sandbox and production
vulkro-sf consistency ./sandbox-metadata ./prod-metadata

SF-SANDBOX-001 flags a sandbox last refreshed more than 180 days ago and SF-SANDBOX-002 a Full sandbox older than 90 days. masking-rules classifies each custom field (PHI, PCI, GDPR special category, financial, government ID, PII) and proposes a masking strategy; it reports no findings and never blocks. See the sandbox refresh docs and masking-rules docs.

FAQ

Does a Salesforce Full sandbox contain production data?

Yes. A Full sandbox copies all production data and metadata unless a sandbox template narrows it. A Partial Copy copies a sample of real records chosen by a template.

Who can log in to a Salesforce sandbox?

By default, every user copied from production, with their production password at the time of the copy. Selective sandbox access limits login to a public group and freezes everyone else.

How do I mask data in a Salesforce sandbox?

Use Salesforce Data Mask or a SandboxPostCopy Apex class, decide per field rather than per object, and run it on every refresh before anyone outside the production access list logs in.

See Vulkro for Salesforce and Start a 14-day trial. Related: your org changed, did its security? and NIS2, DORA and your Salesforce org.