/ sandboxes / code-interpreter / Dockerfile_base
Dockerfile_base
  1  # syntax=docker/dockerfile:1
  2  # Copyright 2025 Alibaba Group Holding Ltd.
  3  #
  4  # Licensed under the Apache License, Version 2.0 (the "License");
  5  # you may not use this file except in compliance with the License.
  6  # You may obtain a copy of the License at
  7  #
  8  #     http://www.apache.org/licenses/LICENSE-2.0
  9  #
 10  # Unless required by applicable law or agreed to in writing, software
 11  # distributed under the License is distributed on an "AS IS" BASIS,
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  # See the License for the specific language governing permissions and
 14  # limitations under the License.
 15  
 16  
 17  FROM ubuntu:24.04
 18  
 19  ARG TARGETARCH
 20  
 21  # Use bash for RUN commands to support source and arrays
 22  SHELL ["/bin/bash", "-c"]
 23  
 24  ENV DEBIAN_FRONTEND=noninteractive \
 25      LANG=C.UTF-8 \
 26      MAVEN_VERSION=3.9.2 \
 27      MAVEN_HOME=/opt/maven \
 28      UV_PYTHON_INSTALL_DIR=/opt/python/versions \
 29      NODE_ROOT=/opt/node \
 30      GO_ROOT=/opt/go \
 31      NODE_V18=18.20.3 \
 32      NODE_V20=20.14.0 \
 33      NODE_V22=22.2.0 \
 34      GO_V1_25=1.25.5 \
 35      GO_V1_24=1.24.11 \
 36      GO_V1_23=1.23.12
 37  
 38  # 1. Install common tools
 39  RUN apt-get update && apt-get install -y --no-install-recommends \
 40      ca-certificates curl wget git vim nano unzip zip tar build-essential \
 41      software-properties-common gnupg lsb-release \
 42      && rm -rf /var/lib/apt/lists/*
 43  
 44  # 2. Install Java (8, 11, 17, 21)
 45  RUN add-apt-repository universe && apt-get update && apt-get install -y --no-install-recommends \
 46      openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk openjdk-21-jdk \
 47      && rm -rf /var/lib/apt/lists/*
 48  
 49  # 3. Install Maven
 50  RUN mkdir -p ${MAVEN_HOME} && \
 51      curl -fsSL https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
 52      | tar -xzC ${MAVEN_HOME} --strip-components=1 && \
 53      ln -s ${MAVEN_HOME}/bin/mvn /usr/local/bin/mvn
 54  
 55  # 4. Install Python (3.10 - 3.14) using uv
 56  RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
 57      mv /root/.local/bin/uv /usr/local/bin/uv && \
 58      mv /root/.local/bin/uvx /usr/local/bin/uvx && \
 59      mkdir -p /opt/python/versions && \
 60      uv python install 3.10 3.11 3.12 3.13 && \
 61      (uv python install 3.14 || echo "Python 3.14 skipped")
 62  
 63  # 5. Install Node.js (18, 20, 22)
 64  RUN mkdir -p ${NODE_ROOT} && \
 65      ARCH="" && \
 66      if [ -z "${TARGETARCH}" ]; then \
 67        case "$(uname -m)" in \
 68          x86_64) TARGETARCH="amd64" ;; \
 69          aarch64) TARGETARCH="arm64" ;; \
 70          *) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; \
 71        esac; \
 72      fi && \
 73      case "${TARGETARCH}" in \
 74        "amd64") ARCH="x64" ;; \
 75        "arm64") ARCH="arm64" ;; \
 76        *) echo "Unsupported architecture: ${TARGETARCH}"; exit 1 ;; \
 77      esac && \
 78      cd ${NODE_ROOT} && \
 79      for v in ${NODE_V18} ${NODE_V20} ${NODE_V22}; do \
 80          curl -fsSL https://nodejs.org/dist/v${v}/node-v${v}-linux-${ARCH}.tar.xz | tar -xJ && \
 81          mv node-v${v}-linux-${ARCH} v${v}; \
 82      done
 83  
 84  # 6. Install Go (latest three major versions)
 85  RUN mkdir -p ${GO_ROOT} && \
 86      ARCH="" && \
 87      if [ -z "${TARGETARCH}" ]; then \
 88        case "$(uname -m)" in \
 89          x86_64) TARGETARCH="amd64" ;; \
 90          aarch64) TARGETARCH="arm64" ;; \
 91          *) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; \
 92        esac; \
 93      fi && \
 94      case "${TARGETARCH}" in \
 95        "amd64") ARCH="amd64" ;; \
 96        "arm64") ARCH="arm64" ;; \
 97        *) echo "Unsupported architecture: ${TARGETARCH}"; exit 1 ;; \
 98      esac && \
 99      cd ${GO_ROOT} && \
100      for v in ${GO_V1_25} ${GO_V1_24} ${GO_V1_23}; do \
101          curl -fsSL https://go.dev/dl/go${v}.linux-${ARCH}.tar.gz | tar -xz && \
102          mv go ${v}; \
103      done
104  
105  # 7. Configure defaults & env script
106  ENV GOROOT=${GO_ROOT}/${GO_V1_25} \
107      PATH="${NODE_ROOT}/v${NODE_V22}/bin:${GO_ROOT}/${GO_V1_25}/bin:${PATH}"
108  
109  RUN mkdir -p /opt/opensandbox
110  COPY scripts/code-interpreter-env.sh /opt/opensandbox/code-interpreter-env.sh
111  RUN chmod +x /opt/opensandbox/code-interpreter-env.sh
112  
113  CMD ["/bin/bash"]