@@ -29,6 +29,8 @@ const sandbox = await Sandbox.create({
2929})
3030```
3131``` python Python
32+ import time
33+
3234from e2b import Sandbox
3335
3436sandbox = Sandbox.create(
@@ -81,17 +83,40 @@ const sandbox = await Sandbox.create({
8183 },
8284})
8385
84- // Example: app source already exists in /home/user/app.
85- // Replace this command with your API server, Next.js, Vite, etc.
8686await sandbox .commands .run (
87- ' cd /home/user/app && npm install && npm run dev -- --host 0.0.0.0 --port 3000' ,
87+ ` python3 -m pip -q install 'flask>=2.2'`
88+ )
89+
90+ await sandbox .files .write (
91+ ' /home/user/app.py' ,
92+ [
93+ ' from flask import Flask' ,
94+ ' app = Flask(__name__)' ,
95+ ' @app.route("/")' ,
96+ ' def hello():' ,
97+ ' return "Hello, World!"' ,
98+ ' app.run(host="0.0.0.0", port=3000)' ,
99+ ' ' ,
100+ ].join (' \n ' )
101+ )
102+
103+ await sandbox .commands .run (
104+ ' python3 -u /home/user/app.py > /home/user/flask.log 2>&1' ,
88105 { background: true }
89106)
90107
108+ await new Promise ((resolve ) => setTimeout (resolve, 1000 ))
109+
91110const previewHost = sandbox .getHost (3000 )
92111console .log (` Preview URL: https://${ previewHost} ` )
112+
113+ console .log (` Status before pause: ${ sandbox .getInfo ().state } ` )
114+ await sandbox .pause ()
115+ console .log (` Status after pause: ${ sandbox .getInfo ().state } ` )
93116```
94117``` python Python
118+ import time
119+
95120from e2b import Sandbox
96121
97122sandbox = Sandbox.create(
@@ -102,15 +127,31 @@ sandbox = Sandbox.create(
102127 },
103128)
104129
105- # Example: app source already exists in /home/user/app.
106- # Replace this command with your API server, Next.js, Vite, etc.
130+ sandbox.commands.run(" python3 -m pip -q install 'flask>=2.2'" )
131+
132+ sandbox.files.write(
133+ " /home/user/app.py" ,
134+ ' from flask import Flask\n '
135+ ' app = Flask(__name__)\n '
136+ ' @app.route("/")\n '
137+ ' def hello():\n '
138+ ' return "Hello, World!"\n '
139+ ' app.run(host="0.0.0.0", port=3000)\n '
140+ )
141+
107142sandbox.commands.run(
108- " cd /home/user/app && npm install && npm run dev -- --host 0.0.0.0 --port 3000 " ,
143+ " python3 -u /home/user/app.py > /home/user/flask.log 2>&1 " ,
109144 background = True ,
110145)
111146
147+ time.sleep(1 )
148+
112149preview_host = sandbox.get_host(3000 )
113150print (f " Preview URL: https:// { preview_host} " )
151+
152+ print (f " Status before pause: { sandbox.get_info().state} " )
153+ sandbox.pause()
154+ print (f " Status after pause: { sandbox.get_info().state} " )
114155```
115156</CodeGroup >
116157
0 commit comments