forked from sillysachin/scira
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.py
More file actions
56 lines (47 loc) · 1.42 KB
/
sandbox.py
File metadata and controls
56 lines (47 loc) · 1.42 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
from daytona import Daytona, DaytonaConfig, Image, CreateSnapshotParams, Resources, CreateSandboxFromSnapshotParams, CodeLanguage
import time
import os
daytona = Daytona(DaytonaConfig(api_key=os.getenv("DAYTONA_API_KEY")))
# Generate a unique name for the image
snapshot_name = f"scira-analysis:{int(time.time())}"
# Create a Python image
image = (
Image.debian_slim("3.12")
.pip_install(["numpy", "pandas", "matplotlib", "scipy", "scikit-learn", "yfinance", "requests", "keras", "uv"])
.run_commands(
"apt-get update && apt-get install -y git",
"groupadd -r daytona && useradd -r -g daytona -m daytona",
"mkdir -p /home/daytona/workspace",
)
)
# Create the image and stream the build logs
print(f"=== Creating Image: {snapshot_name} ===")
daytona.snapshot.create(
CreateSnapshotParams(
name=snapshot_name,
image=image,
resources=Resources(
cpu=2,
memory=4,
disk=5,
),
entrypoint=["sleep", "infinity"],
),
on_logs=print,
)
sandbox = daytona.create(
CreateSandboxFromSnapshotParams(
snapshot="scira-analysis:1751171803",
language=CodeLanguage.PYTHON,
),
)
res = sandbox.process.code_run('''
import yfinance as yf
import matplotlib.pyplot as plt
NVDA = yf.Ticker("NVDA")
data = NVDA.history(period="7d")
print(data)
plt.plot(data['Close'].values)
plt.show()
''')
print(res.result)