---
title: Port a devcontainer.json
description: Turn an existing devcontainer.json into a devsandbox config.
order: 10
icon: file-code
tags: [devcontainers, migration]
related: [features, vscode, isolated-services]
---
import AgentPrompt from '../../components/AgentPrompt.astro';
import AgentPromptLink from '../../components/AgentPromptLink.astro';
## The problem
Your repo already has a `.devcontainer/devcontainer.json` and you want to run it with devsandbox. Rewriting it from scratch risks losing something.
`config.toml` uses the same property names in TOML, so most of the file moves over line by line. The differences: `folder` says which repo the sandbox is for, some properties are ignored, and compose setups become `[services.*]`.
<AgentPromptLink />
## Config
```jsonc title=".devcontainer/devcontainer.json (before)"
{
"name": "web",
"image": "mcr.microsoft.com/devcontainers/typescript-node:22",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"forwardPorts": [3000],
"containerEnv": { "NODE_ENV": "development" },
"mounts": ["source=${localEnv:HOME}/.config/gh,target=/home/node/.config/gh,type=bind"],
"remoteUser": "node",
"postCreateCommand": "npm ci",
"customizations": {
"vscode": {
"extensions": ["dbaeumer.vscode-eslint"],
"settings": { "editor.formatOnSave": true }
}
}
}
```
```toml title="config.toml (after)"
[sandbox.web] # the table key replaces `name`
folder = "../web" # the repo; config.toml lives outside it
image = "mcr.microsoft.com/devcontainers/typescript-node:22"
forwardPorts = [3000] # forwarded while the dashboard is open
containerEnv = { NODE_ENV = "development" }
mounts = ["source=${localEnv:HOME}/.config/gh,target=/home/node/.config/gh,type=bind"]
remoteUser = "node"
postCreateCommand = "npm ci"
# settings: ignored, keep them in the repo's .vscode/settings.json
customizations.vscode.extensions = ["dbaeumer.vscode-eslint"]
[sandbox.web.features]
"ghcr.io/devcontainers/features/github-cli:1" = {}
```
## Try it
From the config dir:
```bash
devsandbox ls # validates the config, no container needed
devsandbox run web
devsandbox exec -it web zsh
```
## How it works
The `devcontainer.json` can stay in the repo; devsandbox never reads it.
### Property mapping
| devcontainer.json | config.toml | notes |
|---|---|---|
| the file's location | `folder` | required by `run` |
| `name` | the table key | `name` is ignored |
| `image`, `features` | same | Features: OCI references only |
| `build.*` | `build = { dockerfile, context, … }` | paths relative to the config dir |
| `containerEnv`, `remoteEnv` | same | `containerEnv` not `${…}`-substituted |
| `containerUser`, `remoteUser` | same | |
| `mounts` | same | missing bind sources are created |
| `workspaceFolder` | same | default `/workspaces/<folder basename>` |
| `workspaceMount` | `folder` | ignored |
| `init`, `privileged` | same | |
| `initializeCommand` | same | runs on the host, in the config dir |
| `onCreateCommand` … `postAttachCommand` | same | tables run in order, not in parallel |
| `customizations.vscode.extensions` | same | |
| `customizations.vscode.settings` | repo `.vscode/settings.json` | ignored |
| `forwardPorts` | same | forwarded by the dashboard while open |
| `appPort`, `portsAttributes` | `devsandbox port web 3000` | ignored |
| `runArgs`, `capAdd`, `securityOpt` | none | ignored |
| `dockerComposeFile`, `service`, `runServices` | `[services.*]` + `services` | error |
### Implemented, ignored, rejected
`ls` errors on unknown keys; `run` warns about ignored ones.
- **Implemented:** `image`, `build`, `features`, `workspaceFolder`, `mounts`, `containerEnv`, `remoteEnv`, `containerUser`, `remoteUser`, `init`, `privileged`, the six lifecycle commands, `customizations.vscode.extensions`, `forwardPorts` ([details](/docs/config#implemented-devcontainer-properties)).
- **Ignored:** `name`, `appPort`, `portsAttributes`, `otherPortsAttributes`, `runArgs`, `workspaceMount`, `overrideFeatureInstallOrder`, `updateRemoteUserUID`, `userEnvProbe`, `overrideCommand`, `shutdownAction`, `capAdd`, `securityOpt`, `hostRequirements`, `waitFor`, `secrets`, other `customizations.*` ([details](/docs/config#accepted-but-ignored-warned-at-run)).
- **Rejected:** `dockerComposeFile`, `service`, `runServices`, and any unknown key.
- **Variables:** as in devcontainers, plus `${configDir}`, `${sharedVolumes}`, `${instance}`; substituted only in some keys ([variables](/docs/config#variables)).
### Coming from docker compose
The app container is the sandbox; each other compose service becomes a `[services.<name>]` (`image`, `env`, `ports`, `command`) that the sandbox lists in `services` and reaches by name as hostname. See [private services per instance](/examples/isolated-services) and [one shared Postgres](/examples/shared-postgres).
## Agent instructions
<AgentPrompt
goal="Port the devcontainer.json of my repo at <repo path> to a sandbox in my devsandbox config.toml."
steps={[
'Read <repo path>/.devcontainer/devcontainer.json and any Dockerfile or docker-compose.yml it references; do not modify them.',
'Add a `[sandbox.<sandbox name>]` with `folder` pointing at <repo path> (relative to the config dir) and copy the implemented properties over; rebase `build` paths onto the config dir. Extend an existing template instead of repeating what it provides.',
'Drop the properties the config-toml-spec lists as ignored and tell me what each did; turn compose services into `[services.*]` listed in `services`.',
]}
verify={[
'Run `devsandbox -C <config dir> run <sandbox name>` and report any `warning:` lines, then `devsandbox -C <config dir> exec <instance> <a command the repo needs>`.',
]}
/>