wiki.getshifting.com

— Sjoerd Hooft's InFormation Technology —

User Tools

Site Tools


vscodedev

VSCode Dev Container Environment

Summary: This wiki page shows how I've setup a VSCode Dev Container setup to safely work without local interaction.
Date: 4 July 2026

You wanna work with AI, but that also implies risks. Working with AI, especially in /yolo mode, the agent could access your local filesystem, network, codebases and what more. So, to contain those risks to an acceptable level, we need an environment in which the agents can roam freely, but can't access any privileged data, or install anything. So, that's where this tutorial comes in. Below I will setup an Azure Linux host, designed to be completely temporal. Inside that remote Linux host, we will create a development container, which will be the base of our development. By setting this up with VS Code, we keep access to our CoPilot Chat and can start development immediately.

Create Azure Linux Host

I have created a terraform module and made it available on my public github repo. It will create a separate resource group, in which a network, subnet, security group with rule for incoming SSH and a Linux Host with already the required software installed.

Note: The instance is a SPOT instance, meaning that it is designed to live short. Any data should be committed to a repository as fast as possible. Also, the instance only has 2 CPU, if you need more, you need to increase the quota for SPOT cpus of your subscription. See the variable “vm_size” for more information.

To start the deployment of the host, make sure to have the files locally. Additionally, make sure to change the values for the following variables:

provider "azurerm" {
  subscription_id = ""
  client_id       = ""
  client_secret   = ""
  tenant_id       = ""
  features {}
}
 
variable "subscription_id" {
  default = ""
}
 
variable "allowed_ssh_cidrs" {
  description = "CIDR ranges allowed to access SSH (port 22)."
  default     = ["x.x.x.x/32"]
}
 
variable "admin_ssh_public_key" {
  default = ""
}

Note that I usually use a Terraform Override File for that. Once setup, you can start the deployment like this:

terraform init
terraform plan
terraform apply -auto-approve

Once the deployment is done, you'll see the output, which you need for the next step.

Setup the SSH Host

Update your C:\Users\<username>\.ssh\config file with the host and the new IP address:

Host vscode
    Hostname <ip address from output>
    User azadmin
    IdentityFile C:\Users\<username>\.ssh\<privatekey>
Note that this IP address will change on each deployment and needs to be updated in the C:\Users\<username>\.ssh\config everytime you redeploy the host.

Connect to the Host from VS Code

To connect to the Host from VSCode run the following command (ctrl+shift+p): Remote-SSH: Connect to Host...

You can also click on the weird prompt icon all the way in the left bottom corner, and then select 'Connect to Host'

The connection opens in a new window and installs vscode-server on the remote vm. When done, you can open a remote folder or just work from the command line. I usually start by cloning the repo I intende to work in. Note that even though you're working on the remote host now, your VS Code still handles a lot for you. So when cloning a GitHub repository, it will ask you if you want to use the GitHub extension for authentication:

git clone https://github.com/getshifting/training.git
cd training

Now we can start vscode on the remote Host:

code -r .

Note, the -r sets to re-use the window you're already working in.

Start the Container

Now we have a fully functional VSCode session running on the remote host, so we are ready to start the development container:

  • From the command menu, select 'Dev Containers: Add Dev Container Configuration Files…'
    • There are many options available, for now we select the PowerShell container. When asked, we also choose to add the 'Azure CLI' as an add-on

This results in a .devcontainer/devcontainer.json:

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/powershell
{
	"name": "PowerShell",
	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
	"image": "mcr.microsoft.com/powershell:lts-debian-11",
	"features": {
		"ghcr.io/devcontainers/features/common-utils:2": {
			"installZsh": "true",
			"username": "vscode",
			"upgradePackages": "false",
			"nonFreePackages": "true"
		},
		"ghcr.io/devcontainers/features/azure-cli:1": {}
	},
 
	"postCreateCommand": "sudo chsh vscode -s \"$(which pwsh)\"",
 
	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": {
				"terminal.integrated.defaultProfile.linux": "pwsh"
			},
 
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": [
				"ms-vscode.powershell"
			]
		}
	}
 
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
 
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}
Note that as we were inside of the repository when we started this, this file can now be committed to the repository and re-used the next time.

Now you can, from the command menu, select 'Dev Containers: Reopen in Container'. This will then use the created .devcontainer/devcontainer.json to create and start the container. Now, you are running a container inside of a remote linux host.

Test the Container

The first time I ran this container I decided to verify I was really running in a container environment, so I asked CoPilot to create a script to quickly validate the environment. That script is available from my public github repo, and will check some characteristics about the environment.

Exit and Cleanup

To exit the container, open the Command Palette (Ctrl+Shift+P) and select “Dev Containers: Reopen Folder Locally”. That disconnects from the container and reopens the same project on your host.

Note: If you only type exit in the terminal, it just closes that shell session, not the VS Code container connection.

Optional cleanup after returning to host:

docker ps
docker stop <container_id>

Finally, you can cleanup the azure deployment using:

terraform destroy

List of Required Extensions

To make sure you can follow along, the following extensions need to be installed in your VS Code:

  • ms-vscode-remote.remote-containers
  • ms-vscode-remote.remote-ssh
  • GitHub.copilot-chat

These are all also listed in my .vscode/extensions.json file.

This wiki has been made possible by:

vscodedev.txt · Last modified: by 127.0.0.1