@@ -13,20 +13,18 @@ import { Template, waitForPort } from 'e2b'
1313
1414export const template = Template ()
1515 .fromUbuntuImage (' 22.04' )
16- // Install SSH server and websocat for WebSocket proxying
17- .aptInstall ([' openssh-server' , ' curl' ])
16+ // Install SSH server, curl for downloading websocat, and sudo for start command
17+ .aptInstall ([' openssh-server' , ' curl' , ' sudo' ])
18+ // Configure SSH and download websocat (requires root)
1819 .runCmd ([
1920 ' curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl' ,
2021 ' chmod a+x /usr/local/bin/websocat' ,
21- ])
22- // Configure SSH with password authentication
23- .runCmd ([
24- ' mkdir -p /run/sshd' ,
2522 " sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config" ,
2623 ' echo "user:sandbox" | chpasswd' ,
27- ])
24+ ' echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers' ,
25+ ], { user: ' root' })
2826 // Start SSH daemon and WebSocket proxy on port 8081
29- .setStartCmd (' /usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22' , waitForPort (8081 ))
27+ .setStartCmd (' sudo mkdir -p /run/sshd && sudo ssh-keygen -A && sudo /usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22' , waitForPort (8081 ))
3028```
3129
3230``` python Python
@@ -36,20 +34,18 @@ from e2b import Template, wait_for_port
3634template = (
3735 Template()
3836 .from_ubuntu_image(" 22.04" )
39- # Install SSH server and websocat for WebSocket proxying
40- .apt_install([" openssh-server" , " curl" ])
37+ # Install SSH server, curl for downloading websocat, and sudo for start command
38+ .apt_install([" openssh-server" , " curl" , " sudo" ])
39+ # Configure SSH and download websocat (requires root)
4140 .run_cmd([
4241 " curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl" ,
4342 " chmod a+x /usr/local/bin/websocat" ,
44- ])
45- # Configure SSH with password authentication
46- .run_cmd([
47- " mkdir -p /run/sshd" ,
4843 " sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config" ,
4944 ' echo "user:sandbox" | chpasswd' ,
50- ])
45+ ' echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers' ,
46+ ], user = " root" )
5147 # Start SSH daemon and WebSocket proxy on port 8081
52- .set_start_cmd(" /usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22" , wait_for_port(8081 ))
48+ .set_start_cmd(" sudo mkdir -p /run/sshd && sudo ssh-keygen -A && sudo /usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22" , wait_for_port(8081 ))
5349)
5450```
5551
0 commit comments