Quickly and easily generate and play with GPT-generated scripts inside of a docker container.

I’ve tossed together a minimal docker container that makes playing with code and Chat-GPT a little more convenient. Provide a language to use, a task to solve, and a filename for the output script and a python script will submit the prompt and spit the output into a sub-folder for you (which is a mounted volume so the output scripts are on your local as well). From there it’s ready to be tweaked and run inside the container. Quickly add dependencies, throw it all away, start again. It’s a quick loop for testing and experimentation.

Download and install Docker or Docker Desktop.

Clone the project from https://github.com/chriscummings/CodePlayground-GPT

Rename the .env.example file to simply .env

Paste your OpenAI API key into the .env file. (Sign up link here), then (API key link here)

Build the base image. docker build -t playground-gpt .

Run the container with a mounted volume. docker run -it -v $(pwd):/code playground-gpt /bin/bash

From here, you’re ready to play. Execute something along the lines of:
python playground-gpt.py <some-language> "<some-task>" <some-filename.ext>

Here I am submitting the following:

python playground-gpt.py javascript "determine days until christmas and set a cookie with the key value pair xmas and days until christmas" xmas.js

A new file, xmas.js is created in the output folder, ready for me to start running it. However, in this example I generated some javascript that needs the run inside a browser (cookies). The code works but requires you to copy & paste it into a browser console. The real value here is staying within the throw-away environment of the container…


I paste two images into the mounted volume of the /output directory.

This time I’ve submitted:

python playground-gpt.py python3 "for a given directory list all child files that are images" x.py

After tweaking the directory path, it worked the first time. Often you have to clean it up a bit to get it to do exactly what you want.

This is a great workspace you can just throw away. Want to run Ruby and NPM? Just update and install anything you need.

apt-get update

apt-get install ruby npm

Edit the requirements.txt and Dockerfiles as needed for a more permanent option.