|
| 1 | +# External workspaces |
| 2 | + |
| 3 | +External workspaces allow you to connect agents running on external infrastructure to your Coder deployment. This feature enables you to bring existing servers, on-premises infrastructure, or any machine that can run the Coder agent into your development environment without requiring Coder to provision the compute resources. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Access to external compute resources (VMs, bare-metal servers, Kubernetes nodes, etc.) that can run the Coder agent. |
| 8 | +- Networking configured so the external agent can reach your Coder deployment. |
| 9 | +- A workspace template that includes a coder_external_agent resource. |
| 10 | +- To import the template and begin configuring it, follow the [documentation in the Coder Registry](https://registry.coder.com/templates/coder-labs/externally-managed-workspace) |
| 11 | + |
| 12 | +## Benefits of external workspaces |
| 13 | + |
| 14 | +External workspaces provide flexibility and control in complex environments: |
| 15 | + |
| 16 | +- **Incremental adoption of Coder** |
| 17 | + |
| 18 | + Connect existing infrastructure without migrating everything at once. |
| 19 | +- **Flexibility** |
| 20 | + |
| 21 | + Attach cloud, hybrid, or on-prem machines as developer workspaces. |
| 22 | +- **Separation of concerns** |
| 23 | + |
| 24 | + Provision compute resources externally (your existing IaC or manual processes) while still using Terraform to manage workspace configuration (apps, scripts). |
| 25 | + |
| 26 | +## Use cases |
| 27 | + |
| 28 | +- Connecting an existing on-premises GPU server for ML development. |
| 29 | +- Bringing a manually provisioned VM in a restricted network under Coder’s workspace management. |
| 30 | +- Gradually migrating workloads to Coder without refactoring current infrastructure. |
| 31 | +- Running agents in CI pipelines to provision short-lived, externally managed workspaces for testing or build automation. |
| 32 | + |
| 33 | +## Known limitations |
| 34 | + |
| 35 | +- **Lifecycle control** |
| 36 | + |
| 37 | + Start/stop/restart actions in the Coder UI are disabled for external workspaces. |
| 38 | +- **No automatic deprovisioning** |
| 39 | + |
| 40 | + Deleting an external workspace in Coder removes the agent token and record, but does not delete the underlying compute resource. |
| 41 | +- **Manual agent management** |
| 42 | + |
| 43 | + Administrators are responsible for deploying and maintaining agents on external resources. |
| 44 | +- **Limited UI indicators** |
| 45 | + |
| 46 | + External workspaces are marked in the UI, but underlying infrastructure health is not monitored by Coder. |
| 47 | + |
| 48 | +## When to use it? |
| 49 | + |
| 50 | +Use external workspaces if: |
| 51 | + |
| 52 | +- You have compute resources provisioned outside of Coder’s Terraform flows. |
| 53 | +- You want to connect specialized or legacy systems to your Coder deployment. |
| 54 | +- You are migrating incrementally to Coder and need hybrid support. |
| 55 | +- You need finer control over how and where agents run, while still benefiting from Coder’s workspace experience. |
| 56 | + |
| 57 | +## How to use it? |
| 58 | + |
| 59 | +You can create and manage external workspaces using either the **CLI** or the **UI**. |
| 60 | + |
| 61 | +### CLI workflow |
| 62 | + |
| 63 | +#### 1. Create an external workspace |
| 64 | + |
| 65 | +```bash |
| 66 | +coder external-workspaces create hello-world \ |
| 67 | + --template=externally-managed-workspace -y |
| 68 | +``` |
| 69 | + |
| 70 | +- Validates that the template includes a `coder_external_agent` resource. |
| 71 | +- Once created, the workspace is registered in Coder but marked as requiring an external agent. |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +#### 2. List external workspaces |
| 76 | + |
| 77 | +```bash |
| 78 | +coder external-workspaces list |
| 79 | +``` |
| 80 | + |
| 81 | +Example output: |
| 82 | + |
| 83 | +```bash |
| 84 | +WORKSPACE TEMPLATE STATUS HEALTHY LAST BUILT CURRENT VERSION OUTDATED |
| 85 | +hello-world externally-managed-workspace Started true 15m happy_mendel9 false |
| 86 | +``` |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +#### 3. Retrieve agent connection instructions |
| 91 | + |
| 92 | +Use this command to query the script you must run on the external machine: |
| 93 | + |
| 94 | +```bash |
| 95 | +coder external-workspaces agent-instructions hello-world |
| 96 | +``` |
| 97 | + |
| 98 | +Example: |
| 99 | + |
| 100 | +```bash |
| 101 | +Please run the following command to attach external agent to the workspace hello-world: |
| 102 | + |
| 103 | +curl -fsSL "https://<DEPLOYMENT_URL>/api/v2/init-script/linux/amd64" | CODER_AGENT_TOKEN="<token>" sh |
| 104 | +``` |
| 105 | + |
| 106 | +You can also output JSON for automation: |
| 107 | + |
| 108 | +```bash |
| 109 | +coder external-workspaces agent-instructions hello-world --output=json |
| 110 | +``` |
| 111 | + |
| 112 | +```json |
| 113 | +{ |
| 114 | + "workspace_name": "hello-world", |
| 115 | + "agent_name": "main", |
| 116 | + "auth_type": "token", |
| 117 | + "auth_token": "<token>", |
| 118 | + "init_script": "curl -fsSL \"https://<DEPLOYMENT_URL>/api/v2/init-script/linux/arm64\" | CODER_AGENT_TOKEN=\"<token>\" sh" |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +### UI workflow |
| 123 | + |
| 124 | +1. Import the external workspace template (see prerequisites). |
| 125 | +2. In the Coder UI, go to **Workspaces → New workspace** and select the imported template. |
| 126 | +3. Once the workspace is created, Coder will display **connection details** with the command users need to run on the external machine to start the agent. |
| 127 | +4. The workspace will appear in the dashboard, but with the following differences: |
| 128 | + - **Start**, **Stop**, and **Restart** actions are disabled. |
| 129 | + - Users are provided with instructions for launching the agent manually on the external machine. |
0 commit comments