1---
2title: Environments
3description: Extra deploy environments under a Project. Production is created with the Project — do not duplicate it.
4---
5
6A [`Railway.Environment`](/providers/railway/environment) is an extra
7deploy environment under a [Project](/railway/compute/projects)
8(staging, preview, …). The production environment is created with
9the Project — do **not** recreate it as an Environment resource.
10
11## Create an extra environment
12
13Alchemy generates a unique name unless you pass one. Production is
14already on the Project as `environmentId`.
15
16```typescript
17const site = yield* Railway.Project("Site");
18const staging = yield* Railway.Environment("Staging", {
19 project: site,
20});
21```
22
23:::note
24Prefer omitting `name` in tests and CI so names stay unique and
25reclaimable.
26:::
27
28## A stable name
29
30Pass `name` when you need a stable environment name (`staging`).
31Changing it later updates the environment in place via
32`environmentRename`.
33
34```typescript
35const staging = yield* Railway.Environment("Staging", {
36 project: site,
37 name: "staging",
38});
39```
40
41## Fork from production
42
43`sourceEnvironmentId` copies services, volumes, configuration, and
44variables from another environment. Create-only.
45
46```typescript
47const staging = yield* Railway.Environment("Staging", {
48 project: site,
49 sourceEnvironmentId: site.environmentId,
50});
51```
52
53## Target an environment from a child
54
55Services, Volumes, Postgres, Redis, Variables, and Buckets default
56to the Project's primary environment. Pass `environment` to put them
57in staging.
58
59```typescript
60const api = yield* Railway.Service("StagingApi", {
61 project: site,
62 environment: staging,
63 image: "hashicorp/http-echo",
64 port: 5678,
65});
66```
67
68:::caution[Changing `project` replaces the Environment]
69The Environment is created in the new Project. The old Environment
70is deleted.
71:::
72
73## Module-scope declarations
74
75Declare the Project once. Pass it into every child.
76
77```typescript
78// src/project.ts
79import * as Railway from "alchemy/Railway";
80
81export const Site = Railway.Project("Site");
82export const Staging = Railway.Environment("Staging", {
83 project: Site,
84});
85```
86
87Resource-valued props accept the resource or an Effect producing it.
88
89## Where next
90
91[Projects](/railway/compute/projects) own the production environment.
92[Services](/railway/compute/services) take `environment`.
93The [`Environment` reference](/providers/railway/environment) lists
94every prop.