1- from e2b import Template , wait_for_port
1+ from e2b import Template , wait_for_port , wait_for_url
22
33
44def make_template (
55 kernels : list [str ] = ["python" , "r" , "javascript" , "deno" , "bash" , "java" ],
6+ set_user_workdir : bool = False ,
67):
78 # Start with base template
89 template = (
910 Template ()
1011 .from_image ("python:3.12" )
12+ .set_user ("root" )
13+ .set_workdir ("/" )
1114 .set_envs (
1215 {
1316 "PIP_DEFAULT_TIMEOUT" : "100" ,
@@ -19,7 +22,7 @@ def make_template(
1922 "R_VERSION" : "4.4.2" ,
2023 "R_HOME" : "/opt/R/4.4.2" ,
2124 "JAVA_HOME" : "/opt/java/openjdk" ,
22- "DENO_INSTALL" : "$HOME/. deno" ,
25+ "DENO_INSTALL" : "/opt/ deno" ,
2326 }
2427 )
2528 .apt_install (
@@ -45,11 +48,7 @@ def make_template(
4548 # Install R Kernel if requested
4649 if "r" in kernels :
4750 template = (
48- template .run_cmd (
49- "curl -O https://cdn.rstudio.com/r/debian-12/pkgs/r-4.4.2_1_amd64.deb"
50- )
51- .apt_install ("./r-4.4.2_1_amd64.deb" )
52- .make_symlink ("/opt/R/4.4.2/bin/R" , "/usr/bin/R" )
51+ template .apt_install ("r-base" )
5352 .run_cmd (
5453 [
5554 "R -e \" install.packages('IRkernel', repos='https://cloud.r-project.org')\" " ,
@@ -70,7 +69,7 @@ def make_template(
7069 template = template .run_cmd (
7170 [
7271 "curl -fsSL https://deno.land/x/install/install.sh | sh" ,
73- "PATH=$HOME/. deno/bin:$PATH" ,
72+ "PATH=/opt/ deno/bin:$PATH" ,
7473 "deno jupyter --unstable --install" ,
7574 ]
7675 )
@@ -113,7 +112,9 @@ def make_template(
113112 .make_dir (".ipython/profile_default/startup" )
114113 .copy ("ipython_kernel_config.py" , ".ipython/profile_default/" )
115114 .copy ("startup_scripts" , ".ipython/profile_default/startup" )
116- .set_start_cmd (".jupyter/start-up.sh" , wait_for_port (49999 ))
117115 )
118116
119- return template
117+ if set_user_workdir :
118+ template = template .set_user ("user" ).set_workdir ("/home/user" )
119+
120+ return template .set_start_cmd (".jupyter/start-up.sh" , wait_for_url ("http://localhost:49999/health" ))
0 commit comments