Building the Code Interpreter Image (mypy)#

Sherpa AIServer uses an isolated Docker container (mypy) as a sandbox to execute Python code. The image contains Python 3.11 and a set of scientific libraries (pandas, numpy, matplotlib, openpyxl, pillow, etc.) and runs under an unprivileged user.

All required files are located in the build/mypy/ directory of the repository.

Requirements#

  • Docker (20.10+)
  • Internet access to download dependencies (or prebuilt wheels — see below)
  • Permissions to run Docker (or sudo)

Prebuilt image (download)#

If you do not need to build the image locally, a prebuilt mypy image can be downloaded together with other images — the download links are listed in the release documents.

Then load the image:

docker load -i mypy_<version>.tar.gz

Building the image#

1. Change to the build directory#

cd build/mypy

2. Build the image#

docker build -t mypy:latest .
💡 Build notes

docker build -t mypy:latest . — builds a Docker image from the Dockerfile in the current directory

  • -t mypy:latest — image tag
  • . — build context

During the build Docker will install all Python packages from requirements.txt via pip install. This requires access to PyPI. For offline builds see the section below.

3. Verify the image was created#

docker images | grep mypy

Expected output:

mypy   latest   <IMAGE_ID>   ...   ~500MB

Saving the image to an archive (for transfer)#

If you need to transfer the image to a target server without internet access:

# In the build/mypy/ directory
docker save mypy:latest -o mypy.tar

The resulting mypy.tar file can be copied to the server via SCP/SFTP and loaded there:

# On the target server — in build/mypy/ or next to mypy.tar
docker load -i mypy.tar

You can also use helper scripts:

# Build and save (developer machine)
bash build/mypy/mypy_build.sh

# Load the image (on the target server)
bash build/mypy/mypy_load.sh

Offline build (no PyPI access)#

If the target server has no internet access, prepare wheels on a machine with internet access:

# On a machine with internet
pip download -r build/mypy/requirements.txt -d build/mypy/wheels/

Then enable offline mode in the build/mypy/dockerfile by copying the wheels and using --find-links:

# Uncomment:
COPY wheels /wheels
RUN pip install --no-index --find-links=/wheels -r requirements.txt

# Comment out:
# RUN pip install -r requirements.txt

And rebuild:

docker build -t mypy:latest build/mypy/

Updating dependencies#

The package list is stored in build/mypy/requirements.txt. To add a new library:

  1. Add the package and version to requirements.txt
  2. Rebuild the image: docker build -t mypy:latest build/mypy/
  3. Restart the code interpreter service in compose: docker compose restart aiserver-code-interpreter

Service integration#

After building the image it is used by the aiserver-code-interpreter service in docker-compose.yml. Ensure the image name in compose matches the tag (mypy:latest).