-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathDockerfile
More file actions
1774 lines (1708 loc) · 110 KB
/
Copy pathDockerfile
File metadata and controls
1774 lines (1708 loc) · 110 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# NemoClaw sandbox image — OpenClaw + NemoClaw plugin inside OpenShell
#
# Layers PR-specific code (plugin, blueprint, config, startup script) on top
# of the pre-built base image from GHCR. The base image contains all the
# expensive, rarely-changing layers (apt, gosu, users, openclaw CLI).
#
# For local builds without GHCR access, build the base first:
# docker build -f Dockerfile.base -t ghcr.io/nvidia/nemoclaw/sandbox-base:latest .
# Global ARG — must be declared before the first FROM to be visible
# to all FROM directives. Can be overridden via --build-arg.
ARG BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:latest
ARG NEMOCLAW_CORPORATE_CA_B64=
# Stage 1: Build TypeScript plugin from source
FROM node:22-trixie-slim@sha256:e6d9a389d34ff9678438af985c9913fbd1eb6ed36e80fea56644f4b4f6dd70ba AS builder
ENV NPM_CONFIG_AUDIT=false \
NPM_CONFIG_FUND=false \
NPM_CONFIG_UPDATE_NOTIFIER=false \
NPM_CONFIG_FETCH_RETRIES=5 \
NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=20000 \
NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=120000 \
NPM_CONFIG_FETCH_TIMEOUT=300000
COPY nemoclaw/package.json nemoclaw/package-lock.json nemoclaw/tsconfig.json /opt/nemoclaw/
WORKDIR /opt/nemoclaw
RUN npm ci
COPY nemoclaw/src/ /opt/nemoclaw/src/
COPY scripts/checks/verify-openshell-policy-boundary-dependencies.mts /opt/nemoclaw-build-checks/
RUN npm run build \
&& node --experimental-strip-types \
/opt/nemoclaw-build-checks/verify-openshell-policy-boundary-dependencies.mts \
/opt/nemoclaw/dist/shared/openshell-policy-boundary.cjs
# Stage 2: Build TypeScript messaging runtime preloads.
FROM builder AS runtime-preload-builder
WORKDIR /opt/nemoclaw-root
COPY tsconfig.runtime-preloads.json /opt/nemoclaw-root/
COPY src/lib/messaging/channels/ /opt/nemoclaw-root/src/lib/messaging/channels/
RUN ln -s /opt/nemoclaw/node_modules /opt/nemoclaw-root/node_modules \
&& /opt/nemoclaw/node_modules/.bin/tsc -p tsconfig.runtime-preloads.json
# Build the agent-neutral, names-only MCP diagnostic once from a committed
# production lock. The final image copies only the bundled runtime, not its
# build-time dependency tree.
FROM node:22-trixie-slim@sha256:e6d9a389d34ff9678438af985c9913fbd1eb6ed36e80fea56644f4b4f6dd70ba AS mcp-tool-discovery-runtime
ARG NEMOCLAW_CORPORATE_CA_B64
ENV AWS_EC2_METADATA_DISABLED=true \
NPM_CONFIG_AUDIT=false \
NPM_CONFIG_FUND=false \
NPM_CONFIG_UPDATE_NOTIFIER=false
WORKDIR /opt/mcp-tool-discovery-runtime
COPY tools/mcp-tool-discovery-runtime/package.json tools/mcp-tool-discovery-runtime/package-lock.json tools/mcp-tool-discovery-runtime/tsconfig.json tools/mcp-tool-discovery-runtime/install-reviewed-runtime.sh tools/mcp-tool-discovery-runtime/*.ts ./
RUN ./install-reviewed-runtime.sh \
&& rm -f ./install-reviewed-runtime.sh
# Group repository-owned files outside the final image so both Docker builders
# can collapse related payloads without invalidating earlier final-image work.
FROM scratch AS openclaw-dependency-payload
COPY agents/openclaw/openclaw-runtime/package.json /usr/local/lib/nemoclaw/openclaw-runtime/package.json
COPY agents/openclaw/openclaw-runtime/package-lock.json /usr/local/lib/nemoclaw/openclaw-runtime/package-lock.json
COPY agents/openclaw/mcporter-runtime/package.json /usr/local/lib/nemoclaw/mcporter-runtime/package.json
COPY agents/openclaw/mcporter-runtime/package-lock.json /usr/local/lib/nemoclaw/mcporter-runtime/package-lock.json
COPY agents/openclaw/wechat-runtime/package.json /usr/local/lib/nemoclaw/wechat-runtime/package.json
COPY agents/openclaw/wechat-runtime/package-lock.json /usr/local/lib/nemoclaw/wechat-runtime/package-lock.json
COPY ci/npm-audit-exceptions.json /scripts/npm-audit-exceptions.json
COPY scripts/lib/reviewed-npm-archive.mts /scripts/lib/reviewed-npm-archive.mts
COPY scripts/lib/reviewed-npm-audit.mts /scripts/lib/reviewed-npm-audit.mts
COPY scripts/lib/openclaw-npm-remediation.mts /scripts/lib/openclaw-npm-remediation.mts
COPY scripts/patch-bundled-npm-brace-expansion.mts /scripts/patch-bundled-npm-brace-expansion.mts
COPY scripts/patch-bundled-npm-tar.mts /scripts/patch-bundled-npm-tar.mts
FROM scratch AS openclaw-plugin-payload
COPY --from=builder /opt/nemoclaw/dist/ /opt/nemoclaw/dist/
COPY nemoclaw/openclaw.plugin.json /opt/nemoclaw/
COPY nemoclaw-blueprint/ /opt/nemoclaw-blueprint/
FROM scratch AS openclaw-patch-payload
COPY scripts/patch-openclaw-tool-catalog.mts /usr/local/lib/nemoclaw/patch-openclaw-tool-catalog.mts
COPY scripts/patch-openclaw-chat-send.mts /usr/local/lib/nemoclaw/patch-openclaw-chat-send.mts
COPY scripts/patch-openclaw-mcp-npx.mts /usr/local/lib/nemoclaw/patch-openclaw-mcp-npx.mts
COPY scripts/patch-openclaw-issue-4434-diagnostics.mts /usr/local/lib/nemoclaw/patch-openclaw-issue-4434-diagnostics.mts
COPY scripts/patch-openclaw-device-self-approval.mts /usr/local/lib/nemoclaw/patch-openclaw-device-self-approval.mts
COPY scripts/extract-semver.sh /usr/local/lib/nemoclaw/extract-semver
COPY scripts/patch-openclaw-shared-state-permissions.mts /usr/local/lib/nemoclaw/patch-openclaw-shared-state-permissions.mts
COPY scripts/verify-wechat-runtime-lock.mts /usr/local/lib/nemoclaw/verify-wechat-runtime-lock.mts
FROM scratch AS openclaw-runtime-payload
COPY scripts/lib/sandbox-init.sh /usr/local/lib/nemoclaw/sandbox-init.sh
COPY scripts/lib/gateway-supervisor.sh /usr/local/lib/nemoclaw/gateway-supervisor.sh
COPY scripts/lib/sandbox-rlimits.sh /usr/local/lib/nemoclaw/sandbox-rlimits.sh
COPY scripts/lib/openclaw_device_approval_policy.py /usr/local/lib/nemoclaw/openclaw_device_approval_policy.py
COPY scripts/lib/clean_runtime_shell_env_shim.py /usr/local/lib/nemoclaw/clean_runtime_shell_env_shim.py
COPY scripts/lib/normalize_mutable_config_perms.py /usr/local/lib/nemoclaw/normalize_mutable_config_perms.py
COPY scripts/state-dir-guard.py /usr/local/lib/nemoclaw/state-dir-guard.py
COPY scripts/openclaw-config-guard.py /usr/local/lib/nemoclaw/openclaw-config-guard.py
COPY scripts/managed-gateway-control.py /usr/local/lib/nemoclaw/managed-gateway-control.py
COPY scripts/nemoclaw-start.sh /usr/local/bin/nemoclaw-start
COPY scripts/gateway-control.sh /usr/local/bin/nemoclaw-gateway-control
COPY nemoclaw-blueprint/scripts/*.js /usr/local/lib/nemoclaw/preloads/
COPY --from=runtime-preload-builder /opt/nemoclaw-root/dist/lib/messaging/channels/ /usr/local/lib/nemoclaw/preloads-compiled-channels/
COPY scripts/codex-acp-wrapper.sh /usr/local/bin/nemoclaw-codex-acp
COPY scripts/generate-openclaw-config.mts /scripts/generate-openclaw-config.mts
COPY scripts/validate-openclaw-tool-search.mts /scripts/validate-openclaw-tool-search.mts
COPY src/lib/tool-disclosure.ts /src/lib/tool-disclosure.ts
COPY src/lib/messaging/ /src/lib/messaging/
COPY nemoclaw-blueprint/openclaw-plugins/ /usr/local/share/nemoclaw/openclaw-plugins/
COPY --from=mcp-tool-discovery-runtime /opt/mcp-tool-discovery-runtime/dist/ /usr/local/lib/nemoclaw/mcp-tool-discovery-runtime/
# Stage 3: Runtime image — pull cached base from GHCR
# hadolint ignore=DL3006
FROM ${BASE_IMAGE}
ARG BASE_IMAGE
# OpenShell blocks the link-local EC2 Instance Metadata Service. Keep AWS SDK
# credential chains from attempting an impossible metadata discovery path.
ENV AWS_EC2_METADATA_DISABLED=true
# Upgrade the final runtime even when an install or rebuild starts from a
# published sandbox base with Node 22.22.2. OpenClaw 2026.7.1 requires the
# SQLite WAL fix in Node 22.22.3 or newer. The trusted managed-image staging
# path removes this one instruction when it has just built Dockerfile.base from
# the same Node image, avoiding a redundant 125 MB layer in that local-only case.
COPY --from=builder /usr/local/bin/node /usr/local/bin/node
# Dependency review evidence for this runtime pin lives in
# docs/security/openclaw-2026.7.1-dependency-review.md.
ARG OPENCLAW_VERSION=2026.7.1
ARG OPENCLAW_2026_7_1_INTEGRITY=sha512-ge/Xss99CHAjPL/ikmH/UFoiOrjcxDB4sW3y9mhyCD+dYW3wzV7TKbAVdkrXFgAG2d2BjpJofP97zUZ+umxo8g==
ARG OPENCLAW_2026_7_1_TARBALL=https://registry.npmjs.org/openclaw/-/openclaw-2026.7.1.tgz
ARG OPENCLAW_DIAGNOSTICS_OTEL_2026_7_1_INTEGRITY=sha512-XXhMifYWTgoR6yFN4T3JkHxdPvQCe8k1cNZjVIgXNmk1svCdBWuALfQQicmpemlmWwauIQuHYgBURY6k63e+rw==
ARG OPENCLAW_BRAVE_PLUGIN_2026_7_1_INTEGRITY=sha512-7Z+GZ/6K6a8LlkTsWVnAZ1hv8EarORzHQvFHD7ekcg033FGJOXYPEZSbvvE3qR9vM+vnoZplNjMZ7vFMRcvQgw==
# E2E-only legacy fixture pins used by stale-sandbox/rebuild tests that
# intentionally build an older OpenClaw base image before proving upgrade
# behavior. Production workflows reject the fixture flag, both legacy version
# values, and these four pin overrides before docker build. Only explicit
# fixture paths may select them; retirement is tracked in #5896 section 9.
ARG NEMOCLAW_E2E_FIXTURE_LEGACY_OPENCLAW=0
ARG OPENCLAW_2026_3_11_INTEGRITY=sha512-bxwiBmHPakwfpY5tqC9lrV5TCu5PKf0c1bHNc3nhrb+pqKcPEWV4zOjDVFLQUHr98ihgWA+3pacy4b3LQ8wduQ==
ARG OPENCLAW_2026_3_11_TARBALL=https://registry.npmjs.org/openclaw/-/openclaw-2026.3.11.tgz
ARG OPENCLAW_2026_4_24_INTEGRITY=sha512-W6u4XeIIP4+uG4DYV9G3JeS6QNuKwfhQIej1GIoL4BdcnUFgrnB8kHYNXL3MxiHRKuhZB9OYwUMGs8jKFZR/Vg==
ARG OPENCLAW_2026_4_24_TARBALL=https://registry.npmjs.org/openclaw/-/openclaw-2026.4.24.tgz
ARG CODEX_ACP_0_11_1_INTEGRITY=sha512-My2VSlBtvJipJhImHjFDej2ut/p00QqOISRnZgLgLrSIzjgvdcQvAhaZviWj7XPhk4UIdIb0OoA+Lrls824uiQ==
# Keep the mcporter version, integrity, runtime lock, license, and advisory baseline
# synchronized with agents/openclaw/dependency-review.md.
ARG MCPORTER_VERSION=0.7.3
ARG MCPORTER_0_7_3_INTEGRITY=sha512-egoPVYqTnWb3NjRIxo+xc8OrAI0dlPrJm9pAiZx0pImuNIV5rKhGtTnIfH/Y1ldGPVu74ibj3KR5c9U/QSdQFA==
ARG MCPORTER_0_7_3_TARBALL=https://registry.npmjs.org/mcporter/-/mcporter-0.7.3.tgz
# A cross-stage root copy is accepted by Docker's legacy builder and creates one
# final-image layer while preserving metadata on existing parent directories.
COPY --from=openclaw-dependency-payload / /
# The final image owns the shipped dependency boundary independently of base
# freshness. Reassert the npm-private node-tar fix here; the helper is
# idempotent for a remediated base and fails closed on unexpected npm layouts.
RUN node --experimental-strip-types /scripts/patch-bundled-npm-tar.mts \
--npm-root /usr/local/lib/node_modules/npm
# Reassert the npm-private brace-expansion fix for the exact final filesystem.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /scripts/patch-bundled-npm-brace-expansion.mts \
--npm-root /usr/local/lib/node_modules/npm
# OpenClaw 2026.7.1 loads some generated source through jiti. Disable its
# filesystem transform cache so source fragments that mention provider marker
# names do not persist under /tmp/jiti inside the sandbox.
ENV JITI_FS_CACHE=false
# Base64-encoded host corporate-proxy CA bundle (#6210). Empty by default. When
# onboard detects an operator-supplied corporate CA on the host it bakes it
# here; the RUN below decodes it to a root-owned file that the entrypoint
# appends to the OpenShell trust bundle at runtime. The CA is a public
# certificate, not a secret, so baking it into an image layer is acceptable.
ARG NEMOCLAW_CORPORATE_CA_B64
# Decode the host corporate-proxy CA (#6210) to a root-owned, read-only file
# when onboard baked one in. No-op when NEMOCLAW_CORPORATE_CA_B64 is empty. The
# ARG is expanded by the shell (not interpolated into source), and its value is
# base64 sanitized host-side, so this is not an injection vector.
# hadolint ignore=DL3059,DL4006
RUN if [ -n "${NEMOCLAW_CORPORATE_CA_B64}" ]; then \
command -v base64 >/dev/null 2>&1 || { echo "[nemoclaw] base64 is required to decode NEMOCLAW_CORPORATE_CA_B64 but is not installed in the build image" >&2; exit 1; }; \
command -v openssl >/dev/null 2>&1 || { echo "[nemoclaw] openssl is required to validate NEMOCLAW_CORPORATE_CA_B64 but is not installed in the build image (#6210)" >&2; exit 1; }; \
mkdir -p /usr/local/share/nemoclaw \
&& { printf '%s' "${NEMOCLAW_CORPORATE_CA_B64}" | base64 --decode > /tmp/nemoclaw-corporate-ca.decoded 2>/dev/null \
|| { echo "[nemoclaw] NEMOCLAW_CORPORATE_CA_B64 is not valid base64; expected a single-line base64-encoded PEM (#6210)" >&2; exit 1; }; } \
&& awk '/-----BEGIN CERTIFICATE-----/{f=1} f{print} /-----END CERTIFICATE-----/{f=0}' /tmp/nemoclaw-corporate-ca.decoded > /usr/local/share/nemoclaw/corporate-ca.pem \
&& rm -f /tmp/nemoclaw-corporate-ca.decoded \
&& { grep -qF -- "-----BEGIN CERTIFICATE-----" /usr/local/share/nemoclaw/corporate-ca.pem || { echo "[nemoclaw] NEMOCLAW_CORPORATE_CA_B64 did not decode to a bundle of valid X.509 certificates (#6210)" >&2; exit 1; }; } \
&& { openssl crl2pkcs7 -nocrl -certfile /usr/local/share/nemoclaw/corporate-ca.pem >/dev/null 2>&1 || { echo "[nemoclaw] NEMOCLAW_CORPORATE_CA_B64 did not decode to a bundle of valid X.509 certificates (#6210)" >&2; exit 1; }; } \
&& chown root:root /usr/local/share/nemoclaw/corporate-ca.pem \
&& chmod 0444 /usr/local/share/nemoclaw/corporate-ca.pem \
&& echo "[nemoclaw] baked host corporate-proxy CA into image trust (#6210)"; \
fi
# Anchor the corporate CA for build-time TLS too, not just runtime. The
# OpenClaw/mcporter reinstall path runs npm audit signatures, which fetches the
# sigstore TUF root over TLS; behind a TLS-intercepting corporate proxy that
# fetch needs the operator CA or it fails with SELF_SIGNED_CERT_IN_CHAIN. Node
# ignores a missing file, so this is a no-op when no CA was baked; at runtime
# nemoclaw-start overrides it with the merged OpenShell + corporate bundle.
ENV NODE_EXTRA_CA_CERTS=/usr/local/share/nemoclaw/corporate-ca.pem
# Harden: remove unnecessary build tools and network probes from base image (#830)
# Protect runtime tools before autoremove — the GHCR base may predate the
# procps/e2fsprogs/tmux additions, leaving ps/chattr/tmux absent or auto-marked.
# The conditional install keeps stale bases usable while fresh bases skip apt.
# tmux is required by OpenClaw's bundled tmux-session flow (#4513); a stale base
# without it makes that flow fail with `tmux: command not found`.
# Refs: #2343, #4513, shields-up chattr hardening
# hadolint ignore=DL3001
RUN set -eu; \
apt-mark manual procps e2fsprogs tmux 2>/dev/null || true; \
(apt-get remove --purge -y gcc gcc-12 g++ g++-12 cpp cpp-12 make \
netcat-openbsd netcat-traditional ncat 2>/dev/null || true); \
apt-get autoremove --purge -y; \
needs_ps=0; \
needs_chattr=0; \
needs_tmux=0; \
if ! command -v ps >/dev/null 2>&1; then needs_ps=1; fi; \
if ! command -v chattr >/dev/null 2>&1; then needs_chattr=1; fi; \
if ! command -v tmux >/dev/null 2>&1; then needs_tmux=1; fi; \
if [ "$needs_ps" = "1" ] || [ "$needs_chattr" = "1" ] || [ "$needs_tmux" = "1" ]; then \
apt-get update; \
if [ "$needs_ps" = "1" ]; then \
apt-get install -y --no-install-recommends procps=2:4.0.4-9; \
fi; \
if [ "$needs_chattr" = "1" ]; then \
apt-get install -y --no-install-recommends e2fsprogs=1.47.2-3+b11; \
fi; \
if [ "$needs_tmux" = "1" ]; then \
apt-get install -y --no-install-recommends tmux=3.5a-3; \
fi; \
fi; \
rm -rf /var/lib/apt/lists/*; \
ps --version; \
command -v chattr >/dev/null; \
command -v tmux >/dev/null
# Install runtime dependencies before copying mutable build outputs so source
# and blueprint changes keep the production dependency layer cached.
COPY nemoclaw/package.json nemoclaw/package-lock.json /opt/nemoclaw/
WORKDIR /opt/nemoclaw
ENV NPM_CONFIG_AUDIT=false \
NPM_CONFIG_FUND=false \
NPM_CONFIG_UPDATE_NOTIFIER=false \
NPM_CONFIG_FETCH_RETRIES=5 \
NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=20000 \
NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=120000 \
NPM_CONFIG_FETCH_TIMEOUT=300000
RUN npm ci --omit=dev
# Copy the grouped plugin and blueprint payload after runtime dependency
# installation so source-only changes do not invalidate that cache boundary.
COPY --from=openclaw-plugin-payload / /
# Copy built plugin and blueprint into the sandbox
RUN chmod -R a+rX /opt/nemoclaw /opt/nemoclaw-blueprint/
# The builder-stage verify-openshell-policy-boundary-dependencies.mts check is
# the primary security gate: it enforces the generated boundary's strict module
# dependency allowlist before this stage copies it. The node check below is
# defense in depth only and proves the copied runtime still exports the complete
# audited interface; function availability does not replace dependency lockdown.
RUN test -f /usr/local/bin/node \
&& test -d /opt/nemoclaw/node_modules/json5 \
&& node -e 'const boundary = require("/opt/nemoclaw/dist/shared/openshell-policy-boundary.cjs"); for (const name of ["parseOpenShellPolicy", "stripProviderComposedPolicies", "withoutProviderComposedPolicies"]) { if (typeof boundary[name] !== "function") throw new Error("OpenShell policy boundary export is unavailable: " + name); }' \
&& node_unsafe="$(find -L /usr/local/bin/node -maxdepth 0 \( ! -user root -o -perm /022 \) -print -quit)" \
&& test -z "$node_unsafe" \
&& json5_unsafe="$(find -L /opt/nemoclaw/node_modules/json5 \( ! -user root -o -perm /022 \) -print -quit)" \
&& test -z "$json5_unsafe"
# Reviewed-archive invariants (#5896): after npm materializes the exact lock and
# seeds resolver metadata, the shared helper re-packs every locked archive
# offline from the final cache and verifies its registry origin, committed SRI,
# and contained filename before the cache becomes immutable.
RUN npm ci --prefix /usr/local/lib/nemoclaw/wechat-runtime \
--ignore-scripts --omit=dev --legacy-peer-deps \
--userconfig /dev/null --registry https://registry.npmjs.org/ \
--cache /usr/local/share/nemoclaw/wechat-npm-cache \
&& npm cache add @tencent-weixin/openclaw-weixin@2.4.3 \
--userconfig /dev/null --registry https://registry.npmjs.org/ \
--cache /usr/local/share/nemoclaw/wechat-npm-cache \
&& npm cache add qrcode-terminal@0.12.0 \
--userconfig /dev/null --registry https://registry.npmjs.org/ \
--cache /usr/local/share/nemoclaw/wechat-npm-cache \
&& npm cache add zod@4.4.3 \
--userconfig /dev/null --registry https://registry.npmjs.org/ \
--cache /usr/local/share/nemoclaw/wechat-npm-cache \
&& NPM_CONFIG_OFFLINE=true \
node --experimental-strip-types /scripts/lib/reviewed-npm-archive.mts \
--lockfile /usr/local/lib/nemoclaw/wechat-runtime/package-lock.json \
--cache /usr/local/share/nemoclaw/wechat-npm-cache \
--registry-origin https://registry.npmjs.org/ \
&& rm -rf /usr/local/lib/nemoclaw/wechat-runtime/node_modules \
&& chown -R root:root /usr/local/lib/nemoclaw/wechat-runtime \
/usr/local/share/nemoclaw/wechat-npm-cache \
&& chmod -R a+rX,go-w /usr/local/lib/nemoclaw/wechat-runtime \
/usr/local/share/nemoclaw/wechat-npm-cache
COPY --from=openclaw-patch-payload / /
RUN chmod 755 /usr/local/lib/nemoclaw/patch-openclaw-tool-catalog.mts \
/usr/local/lib/nemoclaw/patch-openclaw-chat-send.mts \
/usr/local/lib/nemoclaw/patch-openclaw-mcp-npx.mts \
/usr/local/lib/nemoclaw/patch-openclaw-issue-4434-diagnostics.mts \
/usr/local/lib/nemoclaw/patch-openclaw-device-self-approval.mts \
/usr/local/lib/nemoclaw/extract-semver \
/usr/local/lib/nemoclaw/patch-openclaw-shared-state-permissions.mts \
/usr/local/lib/nemoclaw/verify-wechat-runtime-lock.mts
# Pre-install the codex-acp package so the embedded ACPx runtime can
# call the local binary instead of `npx @zed-industries/codex-acp`.
#
# The sandbox's L7 proxy denies @zed-industries/* package URLs
# (403 policy_denied), and npm still refreshes registry metadata for
# versioned npx package specs even when the package is globally installed.
# Installing the binary at build time and configuring ACPx to use it
# directly keeps TC-SBX-02 off the runtime npm path.
# Pack the already-reviewed tarball URL after verifying current registry
# metadata. Re-resolving package@version here would introduce another mutable
# registry selection between the reviewed identity check and installation.
# Reviewed-archive invariants (#5896): registry SRI, packed-byte SRI, contained
# basename in a fresh directory, local-archive-only install, and cleanup.
#
# hadolint ignore=DL3059,DL4006,DL3016
RUN set -eu; \
CODEX_ACP_SPEC='@zed-industries/codex-acp@0.11.1'; \
CODEX_ACP_TARBALL='https://registry.npmjs.org/@zed-industries/codex-acp/-/codex-acp-0.11.1.tgz'; \
CODEX_ACP_PACK_PATH="$(node --experimental-strip-types /scripts/lib/reviewed-npm-archive.mts \
--package-spec "$CODEX_ACP_SPEC" --integrity "$CODEX_ACP_0_11_1_INTEGRITY" \
--tarball-url "$CODEX_ACP_TARBALL" --label "$CODEX_ACP_SPEC")"; \
CODEX_ACP_PACK_DIR="$(dirname "$CODEX_ACP_PACK_PATH")"; \
npm install -g --no-audit --no-fund --no-progress --ignore-scripts \
"$CODEX_ACP_PACK_PATH"; \
rm -rf "$CODEX_ACP_PACK_DIR"; \
command -v codex-acp >/dev/null
# Upgrade OpenClaw if the base image is stale.
# Reuse exact OpenClaw and locked-mcporter base installs only when the protected
# provenance marker matches this build target; otherwise reinstall both.
#
# The GHCR base image (sandbox-base:latest) may lag behind the version pinned in
# Dockerfile.base, and legacy/custom bases may report the target version without
# proving which archive and lifecycle produced it. Current official/local bases
# emit the marker only after installing and auditing both dependencies. The
# final image consumes it before applying NemoClaw patches so it cannot
# masquerade as a pristine base when reused as a custom BASE_IMAGE.
#
# OPENCLAW_VERSION is the NemoClaw runtime build target. It must be at least the
# blueprint minimum, which also supports the legacy direct-blueprint image path.
# Reviewed-archive invariants (#5896): registry SRI, packed-byte SRI, contained
# basename in a fresh directory, local-archive-only install, and cleanup.
# hadolint ignore=DL3059,DL4006,DL3016
RUN set -eu; \
echo "$OPENCLAW_VERSION" | grep -qxE '[0-9]+(\.[0-9]+)*' \
|| { echo "ERROR: OPENCLAW_VERSION='$OPENCLAW_VERSION' is invalid (expected e.g. 2026.3.11)" >&2; exit 1; }; \
MIN_VER=$(grep -m 1 'min_openclaw_version' /opt/nemoclaw-blueprint/blueprint.yaml | awk '{print $2}' | tr -d '"'); \
[ -n "$MIN_VER" ] || { echo "ERROR: Could not parse min_openclaw_version from blueprint.yaml" >&2; exit 1; }; \
if [ "$(printf '%s\n%s' "$MIN_VER" "$OPENCLAW_VERSION" | sort -V | head -n1)" != "$MIN_VER" ]; then \
echo "ERROR: OpenClaw build target ${OPENCLAW_VERSION} is below blueprint minimum ${MIN_VER}" >&2; exit 1; \
fi; \
if [ "$OPENCLAW_VERSION" = "2026.3.11" ] || [ "$OPENCLAW_VERSION" = "2026.4.24" ]; then \
if [ "$NEMOCLAW_E2E_FIXTURE_LEGACY_OPENCLAW" != "1" ]; then \
echo "ERROR: OpenClaw ${OPENCLAW_VERSION} is a legacy E2E fixture pin; set NEMOCLAW_E2E_FIXTURE_LEGACY_OPENCLAW=1 for stale-upgrade fixture builds" >&2; exit 1; \
fi; \
fi; \
EXPECTED_INTEGRITY=""; \
EXPECTED_TARBALL=""; \
if [ "$OPENCLAW_VERSION" = "2026.7.1" ]; then EXPECTED_INTEGRITY="$OPENCLAW_2026_7_1_INTEGRITY"; EXPECTED_TARBALL="$OPENCLAW_2026_7_1_TARBALL"; fi; \
if [ "$OPENCLAW_VERSION" = "2026.3.11" ]; then EXPECTED_INTEGRITY="$OPENCLAW_2026_3_11_INTEGRITY"; EXPECTED_TARBALL="$OPENCLAW_2026_3_11_TARBALL"; fi; \
if [ "$OPENCLAW_VERSION" = "2026.4.24" ]; then EXPECTED_INTEGRITY="$OPENCLAW_2026_4_24_INTEGRITY"; EXPECTED_TARBALL="$OPENCLAW_2026_4_24_TARBALL"; fi; \
if [ -z "$EXPECTED_INTEGRITY" ]; then \
echo "ERROR: OpenClaw ${OPENCLAW_VERSION} has no committed npm integrity pin" >&2; exit 1; \
fi; \
OPENCLAW_LOCK_SHA256=none-legacy-fixture; \
OPENCLAW_RECIPE='ignore-scripts+reviewed-lifecycle-v1'; \
if [ "$OPENCLAW_VERSION" = "2026.7.1" ]; then \
OPENCLAW_LOCK_SHA256=82489f62febb12da52833c0b1f7f6969f7e21a098c565ef1f91342b1e5e32d88; \
ACTUAL_OPENCLAW_LOCK_SHA256="$(sha256sum /usr/local/lib/nemoclaw/openclaw-runtime/package-lock.json | awk '{print $1}')"; \
[ "$ACTUAL_OPENCLAW_LOCK_SHA256" = "$OPENCLAW_LOCK_SHA256" ] \
|| { echo "ERROR: OpenClaw lock SHA-256 mismatch (expected $OPENCLAW_LOCK_SHA256, found $ACTUAL_OPENCLAW_LOCK_SHA256)" >&2; exit 1; }; \
OPENCLAW_RECIPE='locked-ci+reviewed-lifecycle-v2'; \
elif [ "$OPENCLAW_VERSION" = "2026.3.11" ]; then \
OPENCLAW_RECIPE='ignore-scripts+reviewed-lifecycle+transitive-remediation-v1'; \
fi; \
MCPORTER_EXPECTED_INTEGRITY=""; \
MCPORTER_EXPECTED_TARBALL=""; \
if [ "$MCPORTER_VERSION" = "0.7.3" ]; then MCPORTER_EXPECTED_INTEGRITY="$MCPORTER_0_7_3_INTEGRITY"; MCPORTER_EXPECTED_TARBALL="$MCPORTER_0_7_3_TARBALL"; fi; \
if [ -z "$MCPORTER_EXPECTED_INTEGRITY" ]; then \
echo "ERROR: mcporter ${MCPORTER_VERSION} has no committed npm integrity pin" >&2; exit 1; \
fi; \
MCPORTER_LOCK_SHA256="$(sha256sum /usr/local/lib/nemoclaw/mcporter-runtime/package-lock.json | awk '{print $1}')"; \
[ -n "$MCPORTER_LOCK_SHA256" ] \
|| { echo "ERROR: Could not hash the committed mcporter lockfile" >&2; exit 1; }; \
MCPORTER_AUDIT_POLICY_SHA256="$(sha256sum /scripts/npm-audit-exceptions.json | awk '{print $1}')"; \
MCPORTER_EXPECTED_AUDIT_EXCEPTIONS="$(node --experimental-strip-types --input-type=module -e \
'import fs from "node:fs"; import { parseAuditExceptionRegistry } from "/scripts/lib/reviewed-npm-audit.mts"; const policy=parseAuditExceptionRegistry(fs.readFileSync("/scripts/npm-audit-exceptions.json", "utf-8")); const ids=policy.exceptions.filter((entry)=>entry.graph==="mcporter-runtime").map((entry)=>entry.advisory).sort(); process.stdout.write(ids.join(",") || "none");')"; \
MCPORTER_EXPECTED_AUDIT_STATUS=clean; \
if [ "$MCPORTER_EXPECTED_AUDIT_EXCEPTIONS" != "none" ]; then MCPORTER_EXPECTED_AUDIT_STATUS=accepted-exceptions; fi; \
CUR_VER_OUTPUT="$(openclaw --version 2>/dev/null)" \
|| { echo "ERROR: Could not execute openclaw --version" >&2; exit 1; }; \
CUR_VER="$(printf '%s\n' "$CUR_VER_OUTPUT" | /usr/local/lib/nemoclaw/extract-semver openclaw)" \
|| { echo "ERROR: Could not parse OpenClaw version output" >&2; exit 1; }; \
CUR_MCPORTER_VER=$(mcporter --version 2>/dev/null || true); \
CUR_MCPORTER_VER="${CUR_MCPORTER_VER:-0.0.0}"; \
OPENCLAW_PROVENANCE_PATH=/usr/local/share/nemoclaw/openclaw-base-provenance-v1; \
OPENCLAW_EXPECTED_PROVENANCE="$(mktemp)"; \
printf '%s\n' \
'schema=3' \
"package=openclaw@${OPENCLAW_VERSION}" \
"integrity=${EXPECTED_INTEGRITY}" \
"tarball=${EXPECTED_TARBALL}" \
"lock-sha256=${OPENCLAW_LOCK_SHA256}" \
"recipe=${OPENCLAW_RECIPE}" \
"mcporter-package=mcporter@${MCPORTER_VERSION}" \
"mcporter-integrity=${MCPORTER_EXPECTED_INTEGRITY}" \
"mcporter-tarball=${MCPORTER_EXPECTED_TARBALL}" \
"mcporter-lock-sha256=${MCPORTER_LOCK_SHA256}" \
"mcporter-audit-policy-sha256=${MCPORTER_AUDIT_POLICY_SHA256}" \
"mcporter-audit-status=${MCPORTER_EXPECTED_AUDIT_STATUS}" \
"mcporter-audit-exceptions=${MCPORTER_EXPECTED_AUDIT_EXCEPTIONS}" \
'mcporter-recipe=locked-ci+reviewed-audit+signatures-v2' \
> "$OPENCLAW_EXPECTED_PROVENANCE"; \
TRUSTED_BASE_IMAGE=0; \
case "$BASE_IMAGE" in \
ghcr.io/nvidia/nemoclaw/sandbox-base:*|ghcr.io/nvidia/nemoclaw/sandbox-base@sha256:*|nemoclaw-sandbox-base-local|nemoclaw-sandbox-base-local:*) TRUSTED_BASE_IMAGE=1 ;; \
esac; \
USE_REVIEWED_BASE_RUNTIME=0; \
if [ "$TRUSTED_BASE_IMAGE" = "1" ] \
&& [ -f "$OPENCLAW_PROVENANCE_PATH" ] \
&& [ ! -L "$OPENCLAW_PROVENANCE_PATH" ] \
&& [ "$(stat -c '%u:%g:%a' "$OPENCLAW_PROVENANCE_PATH" 2>/dev/null || true)" = "0:0:444" ] \
&& cmp -s "$OPENCLAW_EXPECTED_PROVENANCE" "$OPENCLAW_PROVENANCE_PATH" \
&& [ "$CUR_VER" = "$OPENCLAW_VERSION" ] \
&& [ "$CUR_MCPORTER_VER" = "$MCPORTER_VERSION" ]; then \
USE_REVIEWED_BASE_RUNTIME=1; \
fi; \
rm -f "$OPENCLAW_EXPECTED_PROVENANCE"; \
rm -rf "$OPENCLAW_PROVENANCE_PATH"; \
if [ "$USE_REVIEWED_BASE_RUNTIME" = "1" ]; then \
echo "INFO: Reusing reviewed base OpenClaw $CUR_VER with exact provenance"; \
elif [ "$(printf '%s\n%s' "$OPENCLAW_VERSION" "$CUR_VER" | sort -V | head -n1)" = "$OPENCLAW_VERSION" ] \
&& [ "$CUR_VER" != "$OPENCLAW_VERSION" ]; then \
echo "ERROR: Base image has OpenClaw $CUR_VER, which is newer than reviewed target $OPENCLAW_VERSION" >&2; exit 1; \
else \
echo "INFO: Base image OpenClaw $CUR_VER lacks exact reviewed provenance; installing $OPENCLAW_VERSION"; \
# npm 10's atomic-move install can hit EROFS on overlayfs when the prior
# install spans image layers. Removing it first also prevents unreviewed
# files from surviving a same-version reinstall.
rm -rf /usr/local/lib/node_modules/openclaw /usr/local/bin/openclaw; \
if [ "$OPENCLAW_VERSION" = "2026.7.1" ]; then \
node --experimental-strip-types /scripts/lib/reviewed-npm-archive.mts --verify-lock \
--lock-sha256 "$OPENCLAW_LOCK_SHA256" \
--lockfile /usr/local/lib/nemoclaw/openclaw-runtime/package-lock.json \
--registry-origin https://registry.npmjs.org/ \
--package-spec "openclaw@${OPENCLAW_VERSION}" --integrity "$EXPECTED_INTEGRITY" \
--tarball-url "$EXPECTED_TARBALL" --label "OpenClaw ${OPENCLAW_VERSION}"; \
npm --prefix /usr/local/lib/nemoclaw/openclaw-runtime ci \
--ignore-scripts --omit=dev --no-audit --no-fund --no-progress \
--userconfig /dev/null --registry https://registry.npmjs.org/; \
node --experimental-strip-types /scripts/lib/reviewed-npm-archive.mts \
--verify-installed-lock --lock-sha256 "$OPENCLAW_LOCK_SHA256" \
--lockfile /usr/local/lib/nemoclaw/openclaw-runtime/package-lock.json \
--install-root /usr/local/lib/nemoclaw/openclaw-runtime \
--label "OpenClaw ${OPENCLAW_VERSION}"; \
node /usr/local/lib/nemoclaw/openclaw-runtime/node_modules/openclaw/scripts/postinstall-bundled-plugins.mjs; \
mkdir -p /usr/local/lib/node_modules; \
ln -s /usr/local/lib/nemoclaw/openclaw-runtime/node_modules/openclaw /usr/local/lib/node_modules/openclaw; \
ln -s /usr/local/lib/nemoclaw/openclaw-runtime/node_modules/.bin/openclaw /usr/local/bin/openclaw; \
else \
OPENCLAW_SOURCE_PACK_PATH="$(node --experimental-strip-types /scripts/lib/reviewed-npm-archive.mts \
--package-spec "openclaw@${OPENCLAW_VERSION}" --integrity "$EXPECTED_INTEGRITY" \
--tarball-url "$EXPECTED_TARBALL" --label "OpenClaw ${OPENCLAW_VERSION}")"; \
OPENCLAW_PACK_PATH="$OPENCLAW_SOURCE_PACK_PATH"; \
OPENCLAW_PACK_DIR="$(dirname "$OPENCLAW_PACK_PATH")"; \
if [ "$OPENCLAW_VERSION" = "2026.3.11" ]; then \
OPENCLAW_REMEDIATION_JSON="$(node --experimental-strip-types /scripts/lib/openclaw-npm-remediation.mts \
--archive "$OPENCLAW_SOURCE_PACK_PATH" --package-spec "openclaw@${OPENCLAW_VERSION}" \
--working-directory "$OPENCLAW_PACK_DIR")"; \
OPENCLAW_PACK_PATH="$(node -e 'const value = JSON.parse(process.argv[1]); if (!value.remediated || typeof value.archivePath !== "string") process.exit(1); process.stdout.write(value.archivePath)' "$OPENCLAW_REMEDIATION_JSON")"; \
fi; \
npm install -g --no-audit --no-fund --no-progress --ignore-scripts "$OPENCLAW_PACK_PATH"; \
case "$OPENCLAW_VERSION" in \
2026.4.24) node /usr/local/lib/node_modules/openclaw/scripts/postinstall-bundled-plugins.mjs ;; \
2026.3.11) ;; \
*) echo "ERROR: OpenClaw ${OPENCLAW_VERSION} has no reviewed lifecycle policy" >&2; exit 1 ;; \
esac; \
rm -rf "$OPENCLAW_PACK_DIR"; \
fi; \
fi; \
case "$OPENCLAW_VERSION" in \
2026.3.11) npm ls -g --depth=1 openclaw tar >/dev/null ;; \
esac; \
if [ "$USE_REVIEWED_BASE_RUNTIME" = "1" ]; then \
echo "INFO: Reusing reviewed base mcporter $CUR_MCPORTER_VER with exact lock provenance"; \
else \
node --experimental-strip-types /scripts/lib/reviewed-npm-archive.mts --verify-only \
--package-spec "mcporter@${MCPORTER_VERSION}" --integrity "$MCPORTER_EXPECTED_INTEGRITY" \
--tarball-url "$MCPORTER_EXPECTED_TARBALL" --label "mcporter ${MCPORTER_VERSION}"; \
# Reinstall from the committed lock when exact protected base provenance
# is unavailable; matching top-level versions can hide transitive drift.
echo "INFO: Installing locked mcporter $MCPORTER_VERSION dependency graph"; \
rm -rf /usr/local/lib/node_modules/mcporter /usr/local/bin/mcporter; \
npm --prefix /usr/local/lib/nemoclaw/mcporter-runtime ci \
--ignore-scripts --omit=dev --no-audit --no-fund --no-progress; \
npm --prefix /usr/local/lib/nemoclaw/mcporter-runtime ls \
--omit=dev --all @hono/node-server @modelcontextprotocol/sdk mcporter >/dev/null; \
node --input-type=module -e \
'const { StreamableHTTPServerTransport } = await import("file:///usr/local/lib/nemoclaw/mcporter-runtime/node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js"); const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined }); await transport.close();'; \
ln -s /usr/local/lib/nemoclaw/mcporter-runtime/node_modules/.bin/mcporter /usr/local/bin/mcporter; \
test "$(mcporter --version)" = "$MCPORTER_VERSION"; \
node --experimental-strip-types /scripts/lib/reviewed-npm-audit.mts \
--directory /usr/local/lib/nemoclaw/mcporter-runtime \
--exceptions /scripts/npm-audit-exceptions.json --graph mcporter-runtime --threshold high; \
npm --prefix /usr/local/lib/nemoclaw/mcporter-runtime audit signatures; \
fi
# Patch OpenClaw media fetch for proxy-only sandbox (NVIDIA/NemoClaw#1755).
#
# NemoClaw forces all sandbox egress through the OpenShell L7 proxy
# (default 10.200.0.1:3128). Two layers of OpenClaw must be patched for
# Telegram/Discord/Slack media downloads to work in this environment:
#
# === Patch 1: redirect strict-mode export to trusted-env-proxy ===
# OpenClaw's media fetch path (fetch-ClF-ZgDC.js → fetchRemoteMedia) calls
# fetchWithSsrFGuard(withStrictGuardedFetchMode({...})) unconditionally.
# Strict mode does DNS-pinning + direct connect, which fails in the sandbox
# netns where only the proxy is reachable. Rewriting the fetch-guard module
# export so the strict alias maps to withTrustedEnvProxyGuardedFetchMode
# makes the existing callsite request proxy mode without touching callers.
# The export pattern `withStrictGuardedFetchMode as <letter>` is stable
# across versions while alias letters drift between minified bundles.
# Files that define withStrictGuardedFetchMode locally without an export
# (e.g. mattermost.js) keep their original strict behavior.
#
# === Patch 2: env-gated bypass for assertExplicitProxyAllowed ===
# OpenClaw 2026.4.2 added assertExplicitProxyAllowed() in fetch-guard,
# which validates the explicit proxy URL by passing the proxy hostname
# through resolvePinnedHostnameWithPolicy() with the *target's* SsrfPolicy.
# When the target uses hostnameAllowlist (Telegram media policy:
# `["api.telegram.org"]`), the proxy hostname (e.g. 10.200.0.1) gets
# rejected with "Blocked hostname (not in allowlist)". This is an upstream
# OpenClaw design flaw: a proxy is infrastructure, not a fetch target, and
# should not be filtered through the target's allowlist.
#
# Inject an early-return guarded by `process.env.OPENSHELL_SANDBOX === "1"`
# so the bypass only activates inside an OpenShell sandbox runtime, which
# is what NemoClaw deploys into. OpenShell injects this env var when it
# starts a sandbox pod; any consumer running the same openclaw bundle
# outside an OpenShell sandbox (bare-metal, another wrapper) does not have
# OPENSHELL_SANDBOX set and keeps the full upstream SSRF check. The L7
# proxy itself enforces per-endpoint network policy inside the sandbox,
# so the trust boundary for SSRF protection is unchanged.
#
# Image-level `ENV` does NOT work here: OpenShell controls the pod env at
# runtime and image ENV vars set by Dockerfile are stripped. OPENSHELL_SANDBOX
# is the only marker reliably present in the runtime.
#
# === Patch 2b: allow OpenShell host gateway through web_fetch guard ===
# OpenClaw's web_fetch SSRF guard blocks *.internal hostnames before the
# OpenShell L7 proxy sees the request. NemoClaw users legitimately reach
# host-local approved services through host.openshell.internal after the
# OpenShell policy explicitly allows that host:port. Add this exact hostname
# only to the web_fetch trusted-env-proxy policy, only inside an OpenShell
# sandbox. The generic SSRF helper and strict/direct DNS-pinned paths remain
# unmodified, so metadata/link-local/private IP literals are unchanged.
#
# === Patch 4: route unconfigured strict SSRF fetches through the egress proxy ===
# (NVIDIA/NemoClaw#4687). fetchWithSsrFGuard builds a per-request DNS-pinned
# *direct* undici dispatcher for STRICT-mode fetches that pass no explicit
# dispatcherPolicy — e.g. the @openclaw/googlechat inbound JWT signing-cert
# fetch from www.googleapis.com/service_accounts/v1/metadata/x509/.... A direct
# dispatcher ignores the global EnvHttpProxyAgent installed by
# NODE_USE_ENV_PROXY=1, so the request never reaches the OpenShell L7 proxy and
# fails in the proxy-only sandbox netns — rejecting every inbound Google Chat
# webhook. OpenClaw already has a "managed proxy" branch that routes such
# fetches through the env proxy (createHttp1EnvHttpProxyAgent) while still
# resolving + SSRF-validating the target hostname, but it is gated on
# isManagedProxyActive() (OPENCLAW_PROXY_ACTIVE=1), which NemoClaw does not set.
# Inside an OpenShell sandbox the configured egress proxy IS the managed proxy,
# so extend that activation to OPENSHELL_SANDBOX=1 for fetches that supply no
# explicit dispatcherPolicy. Explicit-proxy and direct(mTLS) dispatcher policies
# (Google auth proxy / client-cert paths) keep their existing behavior, and
# resolvePinnedHostnameWithPolicy still blocks private/link-local targets.
#
# === Removal criteria ===
# Patch 1: drop when OpenClaw deprecates withStrictGuardedFetchMode or
# when all media-fetch callsites unconditionally pass useEnvProxy.
# Patch 2: drop when OpenClaw fixes assertExplicitProxyAllowed to skip the
# target hostname allowlist for the proxy hostname check (or exposes config
# to disable the check).
# Patch 2b: drop when OpenClaw ships a reviewed web_fetch trusted-proxy SSRF
# policy surface that can allow host.openshell.internal without allowing
# broader private/special-use hostnames.
# Patch 4: drop when OpenClaw routes unconfigured strict fetches through the
# env proxy in proxy-only environments without OPENCLAW_PROXY_ACTIVE, or when
# NemoClaw sets OPENCLAW_PROXY_ACTIVE=1 in the sandbox runtime instead.
#
# SYNC WITH OPENCLAW: these patches classify the compiled OpenClaw dist at
# build time. They apply the legacy patch when the old target exists, skip
# only when the dist shape proves OpenClaw no longer needs that patch, and
# fail with the OpenClaw version plus dist path for mixed or unknown shapes.
# When bumping OPENCLAW_VERSION, verify the new dist
# takes the expected branch and update the regex / sed replacement if needed.
# hadolint ignore=SC2016,DL3059,DL4006
RUN set -eu; \
OC_DIST=/usr/local/lib/node_modules/openclaw/dist; \
OC_VERSION_OUTPUT="$(openclaw --version 2>/dev/null)" \
|| { echo "ERROR: Could not execute openclaw --version" >&2; exit 1; }; \
OC_VERSION="$(printf '%s\n' "$OC_VERSION_OUTPUT" | /usr/local/lib/nemoclaw/extract-semver openclaw)" \
|| { echo "ERROR: Could not parse OpenClaw version output" >&2; exit 1; }; \
patch_fail() { \
echo "ERROR: OpenClaw ${OC_VERSION} fetch-guard patch cannot classify this dist shape: $*" >&2; \
echo " Inspect ${OC_DIST} and update the Dockerfile patch rules for this OpenClaw layout." >&2; \
exit 1; \
}; \
# --- Patch 1: rewrite fetch-guard export --- \
fg_export="$(grep -RIlE --include='*.js' 'export \{[^}]*withStrictGuardedFetchMode as [a-z]' "$OC_DIST" || true)"; \
if [ -n "$fg_export" ]; then \
for f in $fg_export; do \
grep -q 'withTrustedEnvProxyGuardedFetchMode' "$f" || patch_fail "Patch 1 target $f is missing withTrustedEnvProxyGuardedFetchMode"; \
done; \
printf '%s\n' "$fg_export" | xargs sed -i -E 's|withStrictGuardedFetchMode as ([a-z])|withTrustedEnvProxyGuardedFetchMode as \1|g'; \
if grep -REq --include='*.js' 'withStrictGuardedFetchMode as [a-z]' "$OC_DIST"; then echo "ERROR: Patch 1 left strict-mode export alias" >&2; exit 1; fi; \
echo "INFO: Patch 1 applied to OpenClaw ${OC_VERSION} strict fetch export"; \
else \
strict_refs="$(grep -RIl --include='*.js' 'withStrictGuardedFetchMode' "$OC_DIST" || true)"; \
trusted_refs="$(grep -RIl --include='*.js' 'withTrustedEnvProxyGuardedFetchMode' "$OC_DIST" || true)"; \
media_fetch_files="$(grep -RIl --include='*.js' 'fetchGuardedMediaResponse' "$OC_DIST" || true)"; \
trusted_media_fetch=0; \
untrusted_media_fetch=0; \
for f in $media_fetch_files; do \
if ! grep -q 'fetchWithSsrFGuard' "$f"; then \
continue; \
elif grep -E 'fetchWithSsrFGuard' "$f" | grep -q 'withTrustedEnvProxyGuardedFetchMode' \
&& ! grep -E 'fetchWithSsrFGuard' "$f" | grep -vq 'withTrustedEnvProxyGuardedFetchMode'; then \
trusted_media_fetch=1; \
else \
echo "ERROR: Patch 1 unreviewed media fetch shape in $f" >&2; \
untrusted_media_fetch=1; \
fi; \
done; \
if [ "$OC_VERSION" != "unknown" ] && [ -z "$strict_refs" ] && [ -n "$trusted_refs" ] && [ "$trusted_media_fetch" = "1" ] && [ "$untrusted_media_fetch" = "0" ]; then \
echo "INFO: OpenClaw ${OC_VERSION} has no withStrictGuardedFetchMode references; Patch 1 not needed"; \
elif [ -z "$trusted_refs" ]; then \
patch_fail "Patch 1 target missing and withTrustedEnvProxyGuardedFetchMode is also absent"; \
else \
echo "ERROR: Patch 1 target missing but the fetch-guard shape is not a reviewed trusted-proxy-only layout:" >&2; \
if [ -n "$strict_refs" ]; then printf '%s\n' "$strict_refs" | head -n 5 >&2; fi; \
patch_fail "Patch 1 cannot safely skip"; \
fi; \
fi; \
# --- Patch 2: neutralize assertExplicitProxyAllowed --- \
fg_assert="$(grep -RIlE --include='*.js' 'async function assertExplicitProxyAllowed' "$OC_DIST" || true)"; \
if [ -n "$fg_assert" ]; then \
patched_assert=0; \
for f in $fg_assert; do \
if grep -q 'process.env.OPENSHELL_SANDBOX === "1"' "$f"; then \
echo "INFO: Patch 2 already present in $f"; \
else \
sed -i -E 's|(async function assertExplicitProxyAllowed\([^)]*\) \{)|\1 if (process.env.OPENSHELL_SANDBOX === "1") return; /* nemoclaw: env-gated bypass, see Dockerfile */ |' "$f"; \
grep -Eq 'assertExplicitProxyAllowed\([^)]*\) \{ if \(process\.env\.OPENSHELL_SANDBOX === "1"\) return; /\* nemoclaw' "$f" \
|| patch_fail "Patch 2 verification failed for $f"; \
patched_assert=1; \
fi; \
done; \
if [ "$patched_assert" = "1" ]; then \
echo "INFO: Patch 2 applied to OpenClaw ${OC_VERSION} explicit proxy validator"; \
fi; \
else \
proxy_hostname_checks="$(grep -RIlE --include='*.js' 'resolvePinnedHostnameWithPolicy' "$OC_DIST" | while IFS= read -r f; do \
if grep -Eq 'parsedProxyUrl|proxyUrl|proxyHostname|proxy.*[Hh]ostname|[Hh]ostname.*proxy|allowPrivateProxy' "$f"; then \
printf '%s\n' "$f"; \
fi; \
done || true)"; \
if [ -z "$proxy_hostname_checks" ]; then \
echo "INFO: OpenClaw ${OC_VERSION} has no assertExplicitProxyAllowed proxy hostname validator; Patch 2 not needed"; \
else \
echo "ERROR: Patch 2 target missing but proxy hostname validation references remain:" >&2; \
printf '%s\n' "$proxy_hostname_checks" | head -n 5 >&2; \
patch_fail "Patch 2 cannot safely skip"; \
fi; \
fi; \
# --- Patch 2b: allow OpenShell host gateway only through web_fetch trusted env proxy --- \
# Reviewed against openclaw@2026.7.1 dist: fetchWithWebToolsNetworkGuard \
# passes useEnvProxy into withTrustedEnvProxyGuardedFetchMode(resolved), and \
# the SSRF guard consumes policy.allowedHostnames to skip private-network \
# checks for an exact normalized hostname. hostnameAllowlist only gates \
# hostname pattern matching and does not bypass .internal/private blocking. \
# Executable fixture proof lives in test/fetch-guard-patch-regression.test.ts; \
# the live network-policy E2E exercises this path in the assembled image. \
web_guard_files="$(grep -RIlE --include='*.js' 'function fetchWithWebToolsNetworkGuard\(params\)' "$OC_DIST" || true)"; \
if [ -n "$web_guard_files" ]; then \
patched_host_gateway=0; \
for f in $web_guard_files; do \
if grep -q 'nemoclaw: OpenShell host gateway for web_fetch trusted env proxy' "$f"; then \
echo "INFO: Patch 2b already present in $f"; \
else \
grep -q 'withTrustedEnvProxyGuardedFetchMode(resolved)' "$f" \
|| patch_fail "Patch 2b target $f is missing reviewed trusted env-proxy web_fetch call"; \
sed -i -E 's|return fetchWithSsrFGuard\(useEnvProxy \? withTrustedEnvProxyGuardedFetchMode\(resolved\) : withStrictGuardedFetchMode\(resolved\)\);|const hostGatewayPolicy = process.env.OPENSHELL_SANDBOX === "1" \&\& useEnvProxy \&\& new URL(resolved.url).hostname === "host.openshell.internal" ? { ...resolved.policy, allowedHostnames: [...resolved.policy?.allowedHostnames ?? [], "host.openshell.internal"] } : resolved.policy; return fetchWithSsrFGuard(useEnvProxy ? withTrustedEnvProxyGuardedFetchMode({ ...resolved, policy: hostGatewayPolicy }) : withStrictGuardedFetchMode(resolved)); /* nemoclaw: OpenShell host gateway for web_fetch trusted env proxy, see Dockerfile */|' "$f"; \
grep -Fq 'process.env.OPENSHELL_SANDBOX === "1" && useEnvProxy && new URL(resolved.url).hostname === "host.openshell.internal"' "$f" \
|| patch_fail "Patch 2b verification failed for $f"; \
patched_host_gateway=1; \
fi; \
done; \
if [ "$patched_host_gateway" = "1" ]; then \
echo "INFO: Patch 2b applied to OpenClaw ${OC_VERSION} web_fetch trusted-proxy host-gateway policy"; \
fi; \
else \
web_fetch_proxy_refs="$(grep -RIlE --include='*.js' 'web_fetch|useEnvProxy|useTrustedEnvProxy|withTrustedEnvProxyGuardedFetchMode\(resolved\)' "$OC_DIST" || true)"; \
if [ -z "$web_fetch_proxy_refs" ]; then \
echo "INFO: OpenClaw ${OC_VERSION} has no web_fetch trusted env-proxy callsite; Patch 2b not needed"; \
else \
echo "ERROR: Patch 2b target missing but web_fetch/trusted-proxy references remain:" >&2; \
printf '%s\n' "$web_fetch_proxy_refs" | head -n 5 >&2; \
patch_fail "Patch 2b cannot safely skip"; \
fi; \
fi; \
# --- Patch 4: route unconfigured strict fetches through the sandbox egress proxy (#4687) --- \
# Reviewed against openclaw@2026.7.1 dist fetch-guard: the STRICT-mode \
# managed-proxy gate is `mode === GUARDED_FETCH_MODE.STRICT && \
# isManagedProxyActive()`. Extend activation to OPENSHELL_SANDBOX=1 only \
# for fetches with no explicit dispatcherPolicy so \
# the per-request direct dispatcher reuses the env proxy (EnvHttpProxyAgent) \
# like the managed-proxy path already does; explicit-proxy / direct dispatcher \
# policies and out-of-sandbox behavior are unchanged. \
mp_files="$(grep -RIlF --include='*.js' 'const isStrictManagedProxyActive = mode === GUARDED_FETCH_MODE.STRICT && isManagedProxyActive();' "$OC_DIST" || true)"; \
if [ -n "$mp_files" ]; then \
patched_managed_proxy=0; \
for f in $mp_files; do \
if grep -q 'nemoclaw: route unconfigured strict fetch' "$f"; then \
echo "INFO: Patch 4 already present in $f"; \
else \
sed -i -E 's#const isStrictManagedProxyActive = mode === GUARDED_FETCH_MODE\.STRICT \&\& isManagedProxyActive\(\);#const isStrictManagedProxyActive = mode === GUARDED_FETCH_MODE.STRICT \&\& (isManagedProxyActive() || (process.env.OPENSHELL_SANDBOX === "1" \&\& !dispatcherPolicy)); /* nemoclaw: route unconfigured strict fetch through sandbox egress proxy, see Dockerfile */#' "$f"; \
grep -Fq 'process.env.OPENSHELL_SANDBOX === "1" && !dispatcherPolicy' "$f" \
|| patch_fail "Patch 4 verification failed for $f"; \
patched_managed_proxy=1; \
fi; \
done; \
if [ "$patched_managed_proxy" = "1" ]; then \
echo "INFO: Patch 4 applied to OpenClaw ${OC_VERSION} managed-proxy strict-fetch activation"; \
fi; \
else \
managed_proxy_refs="$(grep -RIlE --include='*.js' 'canUseManagedProxy|isStrictManagedProxyActive' "$OC_DIST" || true)"; \
if [ -z "$managed_proxy_refs" ]; then \
echo "INFO: OpenClaw ${OC_VERSION} has no managed-proxy strict-fetch gate; Patch 4 not needed"; \
else \
echo "ERROR: Patch 4 target missing but managed-proxy references remain:" >&2; \
printf '%s\n' "$managed_proxy_refs" | head -n 5 >&2; \
patch_fail "Patch 4 cannot safely skip"; \
fi; \
fi; \
# --- Patch 6: cron model-provider preflight opts into trusted env-proxy mode --- \
# Reviewed against openclaw@2026.7.1 dist: the cron isolated-agent preflight \
# (`probeLocalProviderEndpoint`) calls `fetchWithSsrFGuard` with \
# `auditContext: "cron-model-provider-preflight"` and a narrow hostname-allowlist \
# SsrFPolicy from `buildLocalProviderSsrFPolicy`, but does not pass a `mode`. \
# Default STRICT mode pins DNS for the managed inference hostname \
# (`inference.local`), which is intentionally only resolvable through the \
# OpenShell L7 proxy — pinned `dns.lookup` therefore fails with EAI_AGAIN and \
# the scheduler permanently skips every cron run. Inject \
# `mode: "trusted_env_proxy"` so the call uses the env proxy dispatcher; SSRF \
# protection is retained through the existing hostname allowlist and the \
# proxy's own ACLs. \
# \
# The patch keys on the co-located shape of the reviewed preflight call: in \
# any file that mentions the audit context literal, both the \
# `fetchWithSsrFGuard(` helper and the `buildLocalProviderSsrFPolicy` policy \
# builder must appear. The audit-property matcher tolerates quote and same-line \
# whitespace changes; the audit literal itself must appear exactly once; and \
# after patching exactly one patched literal must remain. Any ambiguous \
# multi-callsite or mixed patched/unpatched layout fails the image build \
# rather than silently widening the rewrite. \
# \
# Removal condition: drop this block (and any related `OC_VERSION` floor bump) \
# once an OpenClaw release sets `mode: "trusted_env_proxy"` directly at the \
# preflight call site or otherwise routes the managed inference base URL \
# through the env-proxy dispatcher by default. The reviewed shape lives at \
# `src/cron/isolated-agent/model-preflight.runtime.ts` in the openclaw repo. \
preflight_files="$(grep -RIlF --include='*.js' 'cron-model-provider-preflight' "$OC_DIST" || true)"; \
if [ -n "$preflight_files" ]; then \
patched_preflight=0; \
audit_pattern="auditContext[[:space:]]*:[[:space:]]*(\"cron-model-provider-preflight\"|'cron-model-provider-preflight')"; \
patched_pattern="mode[[:space:]]*:[[:space:]]*(\"trusted_env_proxy\"|'trusted_env_proxy')[[:space:]]*,[[:space:]]*${audit_pattern}"; \
for f in $preflight_files; do \
audit_count="$( { grep -Eo "$audit_pattern" "$f" || true; } | awk 'END { print NR }')"; \
[ "${audit_count:-0}" -ge 1 ] \
|| patch_fail "Patch 6 shape gate: $f mentions cron-model-provider-preflight but has no auditContext literal"; \
[ "${audit_count:-0}" -eq 1 ] \
|| patch_fail "Patch 6 shape gate: $f has ${audit_count} auditContext literals (expected exactly 1); refusing ambiguous multi-callsite rewrite"; \
grep -Fq 'fetchWithSsrFGuard(' "$f" \
|| patch_fail "Patch 6 shape gate: $f has cron-model-provider-preflight but no fetchWithSsrFGuard call"; \
grep -Fq 'buildLocalProviderSsrFPolicy' "$f" \
|| patch_fail "Patch 6 shape gate: $f has cron-model-provider-preflight but no buildLocalProviderSsrFPolicy"; \
patched_count="$( { grep -Eo "$patched_pattern" "$f" || true; } | awk 'END { print NR }')"; \
if [ "${patched_count:-0}" -eq 1 ]; then \
echo "INFO: Patch 6 already present in $f"; \
elif [ "${patched_count:-0}" -eq 0 ]; then \
sed -i -E "s#${audit_pattern}#mode: \"trusted_env_proxy\", &#g" "$f"; \
new_patched_count="$( { grep -Eo "$patched_pattern" "$f" || true; } | awk 'END { print NR }')"; \
[ "${new_patched_count:-0}" -eq 1 ] \
|| patch_fail "Patch 6 verification: expected exactly one patched literal in $f, found ${new_patched_count}"; \
patched_preflight=1; \
else \
patch_fail "Patch 6 shape gate: $f has ${patched_count} already-patched literals (expected 0 or 1); refusing mixed-state rewrite"; \
fi; \
done; \
if [ "$patched_preflight" = "1" ]; then \
echo "INFO: Patch 6 applied to OpenClaw ${OC_VERSION} cron preflight trusted env-proxy"; \
fi; \
else \
preflight_refs="$(grep -RIlE --include='*.js' 'preflightCronModelProvider|probeLocalProviderEndpoint' "$OC_DIST" || true)"; \
if [ -z "$preflight_refs" ]; then \
echo "INFO: OpenClaw ${OC_VERSION} has no cron model-provider preflight; Patch 6 not needed"; \
else \
echo "ERROR: Patch 6 target missing but cron preflight references remain:" >&2; \
printf '%s\n' "$preflight_refs" | head -n 5 >&2; \
patch_fail "Patch 6 cannot safely skip"; \
fi; \
fi; \
# --- Patch 3: follow symlinks in plugin-install path checks (#2203) --- \
# OpenClaw's install-safe-path and install-package-dir reject symlinked \
# directories via lstat. Changing lstat → stat in these two modules lets \
# symlinks resolve; the real security gates (realpath + isPathInside \
# containment) remain intact — a symlink escaping the base tree is still caught. \
# Scoped to install-safe-path + install-package-dir only. \
isp_file="$(grep -RIlE --include='*.js' 'const baseLstat = await fs\.(lstat|stat)\(baseDir\)' "$OC_DIST/install-safe-path-"*.js || true)"; \
test -n "$isp_file" || { echo "ERROR: install-safe-path baseLstat pattern not found" >&2; exit 1; }; \
sed -i 's/const baseLstat = await fs\.lstat(baseDir)/const baseLstat = await fs.stat(baseDir)/' "$isp_file"; \
if grep -q 'const baseLstat = await fs\.lstat(baseDir)' "$isp_file"; then echo "ERROR: Patch 3a (install-safe-path) left baseLstat lstat call" >&2; exit 1; fi; \
if ! grep -q 'const baseLstat = await fs\.stat(baseDir)' "$isp_file"; then echo "ERROR: Patch 3a (install-safe-path) did not find patched baseLstat stat call" >&2; exit 1; fi; \
ipd_file="$(grep -RIlE --include='*.js' 'assertInstallBaseStable' "$OC_DIST/install-package-dir-"*.js || true)"; \
test -n "$ipd_file" || { echo "ERROR: install-package-dir assertInstallBaseStable not found" >&2; exit 1; }; \
if grep -q 'const baseLstat = await fs\.lstat(params\.installBaseDir)' "$ipd_file"; then \
sed -i 's/const baseLstat = await fs\.lstat(params\.installBaseDir)/const baseLstat = await fs.stat(params.installBaseDir)/' "$ipd_file"; \
sed -i 's/baseLstat\.isSymbolicLink()/false \/* nemoclaw: symlink check disabled, realpath guards containment *\//' "$ipd_file"; \
if grep -q 'fs\.lstat(params\.installBaseDir)' "$ipd_file"; then echo "ERROR: Patch 3b (install-package-dir) left lstat in assertInstallBaseStable" >&2; exit 1; fi; \
if ! grep -q 'const baseLstat = await fs\.stat(params\.installBaseDir)' "$ipd_file" && ! grep -q 'await fs\.stat(params\.installBaseDir)).isDirectory()' "$ipd_file"; then echo "ERROR: Patch 3b (install-package-dir) did not find patched/safe installBaseDir stat call" >&2; exit 1; fi; \
if grep -q 'baseLstat\.isSymbolicLink()' "$ipd_file"; then echo "ERROR: Patch 3b (install-package-dir) left baseLstat symlink check" >&2; exit 1; fi; \
else \
grep -q 'await fs\.realpath(params\.installBaseDir) !== params\.expectedRealPath' "$ipd_file" || { echo "ERROR: install-package-dir lacks expected realpath stability guard" >&2; exit 1; }; \
fi; \
# --- Patch 5: bump default WS handshake timeout 10s -> 60s (#2484) --- \
# OpenClaw's WS connect handshake has a hard-coded 10s timeout on both \
# client and server. Server-side connect-handler processing can exceed \
# that limit under load (multiple concurrent connects on slow CI infra), \
# causing `openclaw agent --json` to fail with "gateway timeout after \
# <timeout>ms" and TC-SBX-02 to hit its 90s SSH timeout. \
# \
# Both env vars (OPENCLAW_HANDSHAKE_TIMEOUT_MS, \
# OPENCLAW_CONNECT_CHALLENGE_TIMEOUT_MS) are clamped at the same \
# DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS constant, so we patch the \
# constant itself. Affects both client.js (used by openclaw CLI) and \
# server.impl.js (gateway side). \
# \
# Removal criteria: drop when openclaw fixes the underlying connect \
# latency, or exposes the timeout as an unbounded env override. \
hto_files="$(grep -RIlE --include='*.js' 'DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = (1e4|15e3|6e4)' "$OC_DIST" || true)"; \
test -n "$hto_files" || { echo "ERROR: handshake-timeout constant not found" >&2; exit 1; }; \
printf '%s\n' "$hto_files" | xargs sed -i -E 's#DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = (1e4|15e3)#DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 6e4#g'; \
if grep -REq --include='*.js' 'DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = (1e4|15e3)' "$OC_DIST"; then echo "ERROR: Patch 5 left a short handshake-timeout constant" >&2; exit 1; fi; \
if ! grep -REq --include='*.js' 'DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 6e4' "$OC_DIST"; then echo "ERROR: Patch 5 did not find patched 6e4 constant" >&2; exit 1; fi
# Patch OpenClaw chat.send gateway behavior for OpenClaw 2026.7.1.
#
# OpenClaw can accept rapid TUI/WebChat chat.send requests and then emit a
# terminal chat event with state="final" but no assistant message for the later
# submitted run. That makes clients treat the turn as complete even though no
# visible reply was delivered. The shim also correlates real agent run IDs back
# to the submitted chat.send run ID when OpenClaw starts an internal run with a
# different ID, carries that submitted ID through queued follow-up turns, and
# adds the submitted run ID as the transcript idempotency key.
#
# Removal criteria: drop when upstream OpenClaw fixes openclaw/openclaw#70164
# and openclaw/openclaw#50298, or when NemoClaw no longer ships an affected OpenClaw.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /usr/local/lib/nemoclaw/patch-openclaw-chat-send.mts \
/usr/local/lib/node_modules/openclaw/dist
# Keep OpenClaw 2026.7.1 scope-upgrade approvals inside the gateway's
# canonical locked pairing writer (#4462). The upstream devices CLI otherwise
# asks for the very scopes it is trying to approve, so the handshake fails
# before device.pair.approve runs and its operator.admin retry fails likewise.
# This exact-dist patch allows only a signed, device-token-authenticated CLI to
# approve its own complete operator-only request while it already holds
# operator.pairing; the canonical pairing function repeats identity, role, and
# bounded-scope validation after acquiring its state lock.
#
# Removal criteria: drop when upstream OpenClaw can approve the same bounded
# self-upgrade through the gateway using only operator.pairing.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /usr/local/lib/nemoclaw/patch-openclaw-device-self-approval.mts \
/usr/local/lib/node_modules/openclaw/dist
# Patch OpenClaw TUI unreachable-inference diagnostics for #4434.
#
# OpenClaw 2026.7.1 formats sandbox inference egress failures as either generic
# `TypeError: fetch failed` or `LLM request timed out.` messages, which leave the
# TUI without the required HTTP/cause, gateway/upstream reporting layer, and
# recovery hint fields. This version-scoped shim enriches only those reviewed
# formatter paths, and only inside OpenShell sandboxes where
# OPENSHELL_SANDBOX=1 is supplied at runtime.
#
# Removal criteria: drop when upstream OpenClaw emits these structured fields
# from its assistant error formatter for unreachable inference failures.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /usr/local/lib/nemoclaw/patch-openclaw-issue-4434-diagnostics.mts \
/usr/local/lib/node_modules/openclaw/dist
# Patch OpenClaw's MCP stdio launcher so npx-backed MCP servers run with -y.
# Without this, npx can prompt on cold package resolution and consume the MCP
# JSON-RPC stdin pipe, causing the initialize handshake to time out.
#
# Removal criteria: drop when upstream OpenClaw normalizes npx MCP server args
# and emits actionable MCP startup timeout diagnostics.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /usr/local/lib/nemoclaw/patch-openclaw-mcp-npx.mts \
/usr/local/lib/node_modules/openclaw/dist
# Run the compact tool catalog shim for OpenClaw selection runtimes that still
# need it. OpenClaw 2026.7.1 ships a built-in catalog surface, so the script
# skips cleanly after classifying the compiled selection-*.js shape.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /usr/local/lib/nemoclaw/patch-openclaw-tool-catalog.mts \
/usr/local/lib/node_modules/openclaw/dist
# OpenClaw 2026.7.1 moved gateway startup work into shared and per-agent SQLite
# databases, but hardens them to owner-only modes on every open. NemoClaw's
# root entrypoint runs the CLI and gateway as separate users in the sandbox
# group, so use group-shared modes only when that split-user runtime marker is
# present. Same-UID OpenShell sandboxes retain OpenClaw's private modes. The
# patch leaves generic credential and identity store enforcement unchanged,
# avoids a non-owner chmod when a reviewed shared database mode is already
# safe, keeps generated models files readable by the shared group, and ignores
# the obsolete update-check cache migration that cannot archive across a
# shields-protected parent.
#
# Removal criteria: drop when upstream OpenClaw supports a split-user,
# group-shared state databases and split-user cache migrations without
# startup warnings.
# hadolint ignore=DL3059
RUN node --experimental-strip-types /usr/local/lib/nemoclaw/patch-openclaw-shared-state-permissions.mts \
/usr/local/lib/node_modules/openclaw/dist
# Set up blueprint for local resolution.
# Blueprints are immutable at runtime; DAC protection (root ownership) is applied
# later since /sandbox/.nemoclaw is Landlock read_write for plugin state (#804).
RUN mkdir -p /sandbox/.nemoclaw/blueprints/0.1.0 \
&& cp -r /opt/nemoclaw-blueprint/* /sandbox/.nemoclaw/blueprints/0.1.0/
# Copy the startup scripts and shared sandbox runtime files after setting up the
# blueprint so repository changes retain the intended cache boundary.
# NODE_OPTIONS preload modules use a Landlock-accessible path. OpenShell ≥0.0.36
# blocks /opt/nemoclaw-blueprint/ from non-root users, but the entrypoint
# needs to read these files to install Node runtime preloads under /tmp.
# Channel runtime preloads are authored as TypeScript and compiled in the
# runtime-preload-builder stage before being flattened by filename for --require.
COPY --from=openclaw-runtime-payload / /
RUN discovery_contract="$(node /usr/local/lib/nemoclaw/mcp-tool-discovery-runtime/mcp-tool-discovery.mjs)" \
&& node -e "const result = JSON.parse(process.argv[1]); if (result.protocol !== 1 || result.ok !== false || result.detail !== \"tool discovery received invalid runtime arguments\") process.exit(1);" "$discovery_contract" \
&& discovery_unsafe="$(find -L /usr/local/lib/nemoclaw/mcp-tool-discovery-runtime \( ! -user root -o -perm /022 \) -print -quit)" \
&& test -z "$discovery_unsafe"
# Copy startup script and shared sandbox initialisation library
RUN chmod 755 /usr/local/bin/nemoclaw-start /usr/local/bin/nemoclaw-codex-acp \
/usr/local/lib/nemoclaw/sandbox-init.sh \
/scripts/generate-openclaw-config.mts \
/scripts/validate-openclaw-tool-search.mts \
/src/lib/messaging/applier/build/messaging-build-applier.mts \
&& chmod 444 /src/lib/tool-disclosure.ts \
&& chmod -R a+rX /src/lib/messaging \
&& chown root:root /usr/local/bin/nemoclaw-gateway-control \
/usr/local/lib/nemoclaw/gateway-supervisor.sh \
/usr/local/lib/nemoclaw/state-dir-guard.py \
/usr/local/lib/nemoclaw/openclaw-config-guard.py \
/usr/local/lib/nemoclaw/managed-gateway-control.py \
&& chmod 700 /usr/local/bin/nemoclaw-gateway-control \
&& chmod 500 /usr/local/lib/nemoclaw/state-dir-guard.py \
/usr/local/lib/nemoclaw/openclaw-config-guard.py \
/usr/local/lib/nemoclaw/managed-gateway-control.py \
&& chmod 444 /usr/local/lib/nemoclaw/gateway-supervisor.sh \
/usr/local/lib/nemoclaw/sandbox-rlimits.sh \
&& chmod 644 /usr/local/lib/nemoclaw/openclaw_device_approval_policy.py \
/usr/local/lib/nemoclaw/clean_runtime_shell_env_shim.py \
&& chmod 555 /usr/local/lib/nemoclaw/normalize_mutable_config_perms.py \
&& if [ -d /usr/local/lib/nemoclaw/preloads-compiled-channels ]; then \
find /usr/local/lib/nemoclaw/preloads-compiled-channels -path '*/runtime/*.js' -type f \
-exec sh -c 'for file do cp "$file" "/usr/local/lib/nemoclaw/preloads/$(basename "$file")"; done' sh {} +; \
fi \
&& rm -rf /usr/local/lib/nemoclaw/preloads-compiled-channels \
&& if [ -d /usr/local/lib/nemoclaw/preloads ]; then find /usr/local/lib/nemoclaw/preloads -type f -name '*.js' -exec chmod 644 {} +; fi \
&& chmod 755 /usr/local/share/nemoclaw \
/usr/local/share/nemoclaw/openclaw-plugins \
&& find /usr/local/share/nemoclaw/openclaw-plugins -type d -exec chmod 755 {} + \
&& find /usr/local/share/nemoclaw/openclaw-plugins -type f -exec chmod 644 {} +