Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

5.1 KB
Raw Blame
# Copyright 2026 The OpenSandbox Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "opensandbox-server.fullname" . }}
  namespace: {{ include "opensandbox-server.namespace" . }}
  labels:
    {{- include "opensandbox-server.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.server.replicaCount }}
  strategy:
    type: Recreate
  selector:
    matchLabels:
      {{- include "opensandbox-server.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "opensandbox-server.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/part-of: opensandbox
        {{- with .Values.server.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      annotations:
        # The server parses config.toml once at startup, so an in-place update
        # of the ConfigMap leaves the running pod on the previous configuration.
        # Hashing the rendered TOML rolls the Deployment whenever it changes.
        checksum/config: {{ printf "%s%s" .Values.configToml (include "opensandbox-server.ingressConfigToml" .) | sha256sum }}
        {{- with .Values.server.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "opensandbox-server.serviceAccountName" . }}
      {{- with .Values.server.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.server.podSecurityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.server.priorityClassName }}
      priorityClassName: {{ . }}
      {{- end }}
      {{- with .Values.server.topologySpreadConstraints }}
      topologySpreadConstraints:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: main
          image: {{ include "opensandbox-server.serverImage" . }}
          {{- with .Values.server.containerSecurityContext }}
          securityContext:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          imagePullPolicy: {{ include "opensandbox-server.imagePullPolicy" . }}
          args:
            - "--config"
            - "/etc/opensandbox/config.toml"
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          env:
            - name: SANDBOX_CONFIG_PATH
              value: "/etc/opensandbox/config.toml"
            {{- if and .Values.server.gateway.enabled .Values.server.gateway.secureAccess.existingSecret }}
            # The server builds [ingress.secure_access] from these at startup
            # (OPENSANDBOX_SECURE_ACCESS_* env override), keeping key material
            # out of the config ConfigMap.
            - name: OPENSANDBOX_SECURE_ACCESS_KEYS
              valueFrom:
                secretKeyRef:
                  name: {{ .Values.server.gateway.secureAccess.existingSecret | quote }}
                  key: keys
            - name: OPENSANDBOX_SECURE_ACCESS_ACTIVE_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ .Values.server.gateway.secureAccess.existingSecret | quote }}
                  key: active-key
            {{- end }}
            {{- with .Values.server.env }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          volumeMounts:
            - name: config
              mountPath: /etc/opensandbox/config.toml
              subPath: config.toml
              readOnly: true
            {{- with .Values.server.volumeMounts }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 10
            periodSeconds: 15
            timeoutSeconds: 5
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 3
          resources:
            {{- toYaml .Values.server.resources | nindent 12 }}
      volumes:
        - name: config
          configMap:
            name: {{ include "opensandbox-server.fullname" . }}-config
        {{- with .Values.server.volumes }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      {{- with .Values.server.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.server.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}