# Environments

## Ephemeral Environments

Ephemeral environments enable the creation of temporary environments to assist development and testing. They can be created from a script and can be imported and exported using the mdctl tool.

### Usage

```javascript
import env from 'env'
```

## Provision

Provision using a provisioning token

```javascript
const token = '[Request token from Admin]'

return env.provision({
  org: {
    code: 'env_code',
    name: 'env_name',
    ttl: 10000
  },
  account: {
    email: 'valid@example.com',
    name: {
      first: 'Valid',
      last: 'Example'
    }
  }
}, { token })
```

#### Admin

Provision (admins may provision ephemeral environments without a token)

```javascript
return env.provision({
  org: {
    code: 'env_code',
    name: 'env_name',
    ttl: 10000
  },
  account: {
    email: 'valid@example.com',
    name: {
      first: 'Valid',
      last: 'Example'
    }
  }
})
```

#### provision(data, options)

*Arguments*

* `data` { Object }&#x20;
  * `org` { Object } \[Optional]
    * `code` { String } Environment code.
    * `name` { String } Environment Name.
    * `ttl` { Number } Time to live, will be removed after.
    * `validateOrgCode` { Boolean }
    * `maxApps` { Number } Defaults to 10.
    * `minPasswordScore` { Number }
    * `requireMobile` { Boolean }
  * `account` { Object }
    * `email` { String } \[Required] Account email
    * `name` { Object }
      * `first` { String }
      * `last` { String }
    * `password` { String } \[Optional]
* `options` { Object }
  * `token` { String } Access token

## Teardown

```javascript
return env.teardown('env_code')
```

#### teardown(code, options)

*Arguments*

* `code` { String } Environment code.
* `options` { Object }
  * `token` { String } Access token

## Generate provision token

Service account must have admin role. And `createProvisioningToken` needs to be executed from base org.

```javascript
return env.createProvisioningToken('apiKey', 'c_name_of_service_account')
```

#### createProvisioningToken(apiKey, serviceAccountName, options)

*Arguments*

* `apiKey` { String } Application key or name.
* `serviceAccountName` { String } Name of an admin service account.
* `options` { Object } \[Optional]
  * `skipAcl` { Boolean }
  * `bypassCreateAcl` { Boolean }
  * `grant` { Number }
  * `permanent` { Boolean }
  * `activatesIn` { Date }
  * `validAt` { Date }
  * `expiresIn` { Date }
  * `isSupportLogin` { Boolean }
  * `maxUses` { Number }

### Import/Export

Import ephemeral environment

```bash
mdctl env import --env [environment_name]
```

Export ephemeral environment

```bash
mdctl env export --env [environment_name]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/scripting/environments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
