Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
95 lines (81 loc) · 3.87 KB
/
Copy pathDockerfile
File metadata and controls
95 lines (81 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright 2026 The Kubernetes 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.
# Multi-stage build: compile envd from upstream E2B source, then package
# into a minimal runtime image with GNU userland (needed for process exec).
#
# Build:
# docker build -t envd-sandbox:latest .
# docker build -t envd-sandbox:latest --build-arg ENVD_VERSION=main .
# Stage 1: Build envd binary from e2b-dev/runtime source (formerly e2b-dev/infra;
# the repo was renamed and its history restructured in Sep 2026).
# NOTE: For production use, pin ENVD_VERSION to a specific commit or release
# tag (e.g., --build-arg ENVD_VERSION=v0.1.0 or a commit hash) instead of
# tracking the moving `main` branch.
FROM --platform=$BUILDPLATFORM golang:1.27.1 AS builder
# Pinned to a known-good release tag, with the resolved commit verified below.
# Override with --build-arg ENVD_VERSION=<ref> to track upstream or pin to a
# different revision (also override ENVD_COMMIT, or set it empty to skip the
# commit check).
# Tags survive upstream rebases where bare SHAs do not: the infra->runtime
# rename rewrote history and orphaned the previously pinned SHA, breaking this
# build. The commit check restores immutability — if upstream ever moves the
# tag, the build fails loudly instead of silently compiling different code.
ARG ENVD_VERSION=envd-v0.6.13
ARG ENVD_COMMIT=2acf2d51bd1e2fe146914f24c44f7ee07d2213c5
ARG TARGETARCH=amd64
WORKDIR /src
# envd lives under packages/envd in the e2b-dev/runtime monorepo.
# Clone then checkout supports branches, tags, and commit hashes.
RUN git clone https://github.com/e2b-dev/runtime.git /src/infra \
&& cd /src/infra \
&& git checkout ${ENVD_VERSION} \
&& if [ -n "${ENVD_COMMIT}" ] && [ "$(git rev-parse HEAD)" != "${ENVD_COMMIT}" ]; then \
echo "ERROR: ${ENVD_VERSION} resolved to $(git rev-parse HEAD), expected ${ENVD_COMMIT} — upstream tag moved"; \
exit 1; \
fi
WORKDIR /src/infra/packages/envd
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GOWORK=off GOTOOLCHAIN=auto \
go build -ldflags="-s -w" -trimpath -o /out/envd .
# Stage 2: Runtime image with GNU userland for process exec support.
# NOTE: debian:12-slim == debian:bookworm-slim (same image, different tag).
FROM debian:12-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
bash \
coreutils \
findutils \
grep \
sed \
tar \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /out/envd /usr/local/bin/envd
# Create a non-root user for subprocess execution.
# Following the e2b-dev debug.Dockerfile pattern:
# https://github.com/e2b-dev/runtime/blob/main/packages/envd/debug.Dockerfile
#
# Security model: envd runs as root (required for PTY, process management),
# but user code spawned via /init's defaultUser runs as this unprivileged user.
# This limits blast radius if user code is malicious.
RUN useradd -ms /bin/bash user
RUN chmod 777 -R /home/user
WORKDIR /home/user
# 49983 is envd's default HTTP/gRPC port.
EXPOSE 49983
# --isnotfc : skip Firecracker MMDS polling (we're running in a plain
# container, not a Firecracker microVM).
# --no-cgroups : skip cgroup v2 setup (not available in sandbox containers).
# --verbose : useful for debugging; remove in production.
ENTRYPOINT ["/usr/local/bin/envd"]
CMD ["--isnotfc", "--no-cgroups", "--port", "49983", "--verbose"]