# Create an Agentforce-Ready Scratch Org With Salesforce CLI

This guide describes the basic steps for using Salesforce CLI to create a generative AI scratch org for a Developer or Enterprise edition org. You can use either a [sandbox or a scratch org](/docs/ai/agentforce/guide/agent-dx-set-up-env.md#sandbox-versus-scratch-org) to develop and test your agents. If your agent needs Agentforce Data Library (ADL) or other Data 360 features, we recommend using a sandbox. For more information on the Agentforce developer lifecycle, see [Build Agents with Agentforce DX](/docs/ai/agentforce/guide/agent-dx.md)

:::note
A [scratch org](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs.htm) is a configurable, short-term Salesforce environment that you can quickly spin up when starting a new project, a new feature branch, or a feature test. Unlike a sandbox, a scratch org doesn't contain data or metadata from your production org. Scratch orgs are configured using a scratch org definition file, which lists the features and settings that mirror the customer's production org.
:::

1. Install [Salesforce CLI](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm) on your computer.

2. Open a terminal (macos, Linux) or command prompt (Windows) and make sure that Salesforce CLI is up to date by running this command.

   ```sfdocs-code {"lang":"bash", "title": "Update CLI"}
   sf update
   ```

3. (Optional) [Create a Salesforce DX project](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm) on your computer and change to the directory.

   If you only want to create a scratch org, then this step isn't necessary. But we recommend creating a DX project if you plan to store your org’s metadata (code and configuration), org templates, sample data, and tests in a version control system. See [Project Setup](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_workspace_setup.htm).

4. Select and enable your Dev Hub org, which must have your Data 360 licenses. See [Select and Enable a Dev Hub Org](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_setup_enable_devhub.htm) in the Salesforce DX Developer Guide for more information.

5. Log in to your Dev Hub org and allow access. In the browser window that opens, sign in to your org with your Salesforce login credentials. Click **Allow**, which allows Salesforce CLI to access to your org.

   ```sfdocs-code {"lang":"bash", "title": "Allow Access"}
   sf org login web --set-default-dev-hub --alias DevHub
   ```

6. Create a definition file, such as `afdx-scratch-def.json`. If you're using a Salesforce DX project, create the file in the `config` directory alongside the existing `config/project-scratch-def.json` file.

   To use an Einstein Generative AI scratch org, add the `Einstein1AIPlatform` feature, which is supported in Developer and Enterprise editions. To automatically enable Einstein and Agentforce, turn on the `agentPlatformSettings.enableAgentPlatform` and `einsteinGptSettings.enableEinsteinGptPlatform` settings.

   ```sfdocs-code {"lang":"json", "title": "Sample Scratch Org Definition File"}
   {
     "orgName": "Agentforce scratch org",
     "edition": "Developer",
     "features": ["EnableSetPasswordInApi","Einstein1AIPlatform"],
     "settings": {
       "lightningExperienceSettings": {
         "enableS1DesktopEnabled": true
       },
       "mobileSettings": {
         "enableS1EncryptedStoragePref2": false
       },
       "agentPlatformSettings": {
         "enableAgentPlatform": true
       },
       "einsteinGptSettings" : {
         "enableEinsteinGptPlatform" : true
       }
     }
   }
   ```

7. Using the scratch org definition file, create the scratch org.

   ```sfdocs-code {"lang":"bash", "title": "Create Scratch Org"}
   sf org create scratch --definition-file config/afdx-scratch-def.json --alias MyScratchOrg --set-default --target-dev-hub DevHub
   ```

8. Open the org.

   ```sfdocs-code {"lang":"bash", "title": "Open Scratch Org"}
   sf org open --target-org MyScratchOrg
   ```

After you open the org, you can use Salesforce generative AI features such as Agentforce, Prompt Builder, Model Builder, and the Models API. To learn more, see [Agentforce and Einstein Generative AI](https://help.salesforce.com/s/articleView?id=ai.generative_ai.htm) in Salesforce Help.

## See Also

- [Set Up Einstein Generative AI and Agentforce](/docs/ai/agentforce/guide/org-setup.md)
- [AgentPlatformSettings Metadata API](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_agentplatformsettings.htm)
- [EinsteinGptSettings Metadata API](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_einsteingptsettings.htm)
