1
- """ Modal utility functions
1
+ """Modal utility functions
2
2
3
3
A mirror of the docker utility functions.
4
4
"""
5
5
6
6
import modal
7
7
import os
8
+ from pathlib import Path
8
9
9
- from commit0 .harness .docker_utils import HEREDOC_DELIMITER
10
10
11
-
12
- def create_sandbox ( image : modal . Image , nfs : model . NetworkFileSystem ) -> modal . Sandbox :
11
+ def create_sandbox ( image : modal . Image , nfs : modal . NetworkFileSystem ) -> modal . Sandbox :
12
+ """Create modal sandbox"""
13
13
return modal .Sandbox .create (
14
14
"sleep" ,
15
15
"infinity" ,
@@ -20,7 +20,10 @@ def create_sandbox(image: modal.Image, nfs: model.NetworkFileSystem) -> modal.Sa
20
20
)
21
21
22
22
23
- def execute_command (sandbox : modal .Sandbox , command : str , timeout = ) -> tuple [str ,str ]:
23
+ def execute_command (
24
+ sandbox : modal .Sandbox , command : str , timeout : int = 90
25
+ ) -> tuple [str , str ]:
26
+ """Execute command on modal sandbox"""
24
27
process = sandbox .exec ("bash" , "-c" , command )
25
28
stdout = []
26
29
for line in process .stdout :
@@ -31,21 +34,27 @@ def execute_command(sandbox: modal.Sandbox, command: str, timeout=) -> tuple[str
31
34
return "\n " .join (stdout ), "\n " .join (stderr )
32
35
33
36
34
- def copy_file_to_sandbox (sandbox : modal .Sandbox , nfs : modal .NetworkFileSystem , src : Path , dst : Path ) -> None :
37
+ def copy_file_to_sandbox (
38
+ sandbox : modal .Sandbox , nfs : modal .NetworkFileSystem , src : Path , dst : Path
39
+ ) -> None :
40
+ """Copy file to modal sandbox"""
35
41
with src .open ("rb" ) as f :
36
42
nfs .write_file (str (src ), f )
37
43
sandbox .exec ("bash" , "-c" , f"cp /vol/{ str (src )} { str (dst )} " )
38
44
39
45
40
46
def copy_from_sandbox (sandbox : modal .Sandbox , src : Path , dst : Path ) -> None :
47
+ """Copy file from sandbox"""
41
48
pass
42
49
43
50
44
51
def delete_file_from_sandbox (sandbox : modal .Sandbox , file_path : str ) -> None :
52
+ """Delete file on sandbox"""
45
53
pass
46
54
47
55
48
56
def copy_ssh_pubkey_from_sandbox (sandbox : modal .Sandbox ) -> None :
57
+ """Copy SSH public key from sandbox"""
49
58
process = sandbox .exec ("bash" , "-c" , "cat /root/.ssh/id_rsa.pub" )
50
59
public_key = "" .join ([line for line in process .stdout ]).strip ()
51
60
@@ -69,4 +78,5 @@ def copy_ssh_pubkey_from_sandbox(sandbox: modal.Sandbox) -> None:
69
78
70
79
71
80
def write_to_sandbox (sandbox : modal .Sandbox , data : str , dst : Path ) -> None :
81
+ """Write file to sandbox"""
72
82
pass
0 commit comments