Add support for devcontainers to facilitate GitHub Codespaces usage?

As announced earlier this month, every GitHub user now gets 120 free hours of Codespaces compute (GitHub’s hosted compute solution). That means you can get:

  • 60 hours with a 2-core instance
  • 30 hours with a 4-core instance
  • 15 hours with 8 cores
  • ~7 hours with 16 cores

The interesting thing here is that the 2-core instance is definitely enough for a week of sprinting and not run out of quota! Because of this, I would like to propose we make using Codespaces easy by adding the appropriate devcontainer configuration files to GitHub - python/cpython: The Python programming language .

First, a disclaimer: I do work for Microsoft on the VS Code team. That means I work for the company providing the free compute and on the team that defines the devcontainer spec. I do not work on Codespaces, but the VS Code team itself does work with them closely (not me personally, though). But I am doing this because I think it would be a benefit for us, not to sell anyone anything.

With that out of the way, what I’m proposing is that we (at least) add a devcontainer.json to the repo that specifies how to build a container to develop for CPython. The nice thing about doing this is we can make sure that contributors are set up from the start with the right tools to develop for CPython. This can even include setting up autoconf appropriately for even seasoned core developers. :wink: We can even get toolchains like for WebAssembly set up in the container so that even that is supported. The key thing here is it would let us make sure a Linux environment is always available that people can use to develop for Python without having to figure out what to install. And this works both locally via Docker or in Codespaces, so a potential win even for those not wanting to use hosted compute from GitHub. And the devcontainers.json can pretty much just point to a Dockerfile that we maintain, so there isn’t any vendor lock-in here.

After that we can consider setting up pre-builds for Codespaces. What that does is it re-builds the container image via a GitHub Action whenever we want; we can have it do it after every commit, once a day, whatever. But the key thing is we can make it such that building CPython from a pre-built devcontainer is extremely fast (if not instantaneous if we pre-build after every commit so there’s actually nothing to build until you edit the code). Much like making sure new contributors have the tools they need to build CPython with devcontainer.json, this would help facilitate new contributors by getting them going even faster and knowing that the build was already successful and usable.

Finally, and this might be the most controversial, we could configure the devcontainer for VS Code / . Since devcontainers can contain tool-specific settings we can add VS Code settings and extension recommendations so that folks have appropriate settings for things like indentation, etc. The only reason I’m suggesting this is that with https::/ / it would allow folks to develop entirely via a browser during sprints using Codespaces, no local setup required. To be clear, though, this is not required and you can even use Codespaces with other editors like PyCharm. But as I said, this would let someone to show up with a Chromebook at a sprint and be able to get work done quickly.

So, what do people think? I know we have a general policy of not putting tool-specific stuff in the repo, but I think the benefits of all of this are great enough to consider at least the devcontainer.json bit and probably the pre-builds. Obviously I would love to also add the stuff to make using work, but I understand if people feel that’s too tool-specific.


I like it.

FYI, Microsoft provides devcontainer config for cpython now. So we can start using Codespace for cpython already.
Adding devcontainer config to our repository means we maintain it instead of Microsoft.

This is devcontainer config for cpython.

1 Like

Correct, we can make changes faster and they can be appropriate to the Python version in case we change things, e.g. what version of autoconf we want to use.

1 Like

I talked this idea over with the SC to make sure there wasn’t any inherent bias on my part. In the end, the discussion came to the conclusion that this was a reasonable idea to follow through with for the benefit of sprints and people wanting to make quick edits.


I have a branch at cpython/.devcontainer at dev-container · brettcannon/cpython · GitHub configured. I am just testing pre-builds to make sure they do what I expect them to do, and then I will open a PR.


Is it Codespace-only? Or are you testing general devcontainer environment?

As far as I know, workspaceFolder is mandatory for general devcontainer, but not for Codespace.


It all works fine for me locally via Docker, so I don’t think it’s necessary.

Opened the PR at GH-102973: add a dev container by brettcannon · Pull Request #102975 · python/cpython · GitHub (which also has an accompanying issue).