@@ -75,6 +75,35 @@ chown -R user:user /home/user
7575echo " Give 777 permission to /usr/local"
7676chmod -R 777 /usr/local
7777
78+ # The 777 above is what lets sandbox users install into /usr/local without
79+ # sudo, but it also lets them delete or replace the E2B helpers root runs at
80+ # boot (envd's ExecStartPre). Sticky keeps that convenience — anyone can still
81+ # create files here — while restricting unlink/rename to a file's owner, so the
82+ # root-owned helpers below cannot be swapped out. Defense in depth: 'user'
83+ # already has NOPASSWD sudo, so this is not a privilege boundary.
84+ # The whole ancestor chain needs it, not just the leaves: a sticky directory
85+ # whose parent is world-writable and non-sticky can be renamed aside wholesale
86+ # and recreated with replaced contents.
87+ echo " Set the sticky bit on the directories holding root-executed E2B helpers"
88+ for dir in /usr/local /usr/local/bin /usr/local/share /usr/local/share/e2b; do
89+ if [ -d " $dir " ]; then
90+ chmod 1777 " $dir "
91+ fi
92+ done
93+ echo " Restore root-owned, non-writable modes on the E2B helpers"
94+ for exe in /usr/local/bin/e2b-seed-certs /usr/local/bin/e2b-provision-runner /usr/local/share/e2b/envd.openrc; do
95+ if [ -f " $exe " ]; then
96+ chown root:root " $exe "
97+ chmod 755 " $exe "
98+ fi
99+ done
100+ # distro.env is sourced by root here and by later FROM-template builds.
101+ # ssl-certs.tar is packed after this script runs, so it is hardened there.
102+ if [ -f /usr/local/share/e2b/distro.env ]; then
103+ chown root:root /usr/local/share/e2b/distro.env
104+ chmod 644 /usr/local/share/e2b/distro.env
105+ fi
106+
78107echo " Create /code directory"
79108mkdir -p /code
80109echo " Give 777 permission to /code"
0 commit comments