@@ -503,8 +503,9 @@ def exec(
503503 no_login_shell : bool = False ,
504504 ) -> ExecResult :
505505 return self ._client .exec (
506- self .sandbox .id ,
506+ self .sandbox .name ,
507507 command ,
508+ workspace = self ._workspace ,
508509 stream_output = stream_output ,
509510 workdir = workdir ,
510511 env = env ,
@@ -525,8 +526,9 @@ def exec_python(
525526 timeout_seconds : int | None = None ,
526527 ) -> ExecResult :
527528 return self ._client .exec_python (
528- self .sandbox .id ,
529+ self .sandbox .name ,
529530 function ,
531+ workspace = self ._workspace ,
530532 args = args ,
531533 kwargs = kwargs ,
532534 stream_output = stream_output ,
@@ -766,10 +768,10 @@ def create(
766768 request_spec = spec if spec is not None else _default_spec ()
767769 response = self ._stub .CreateSandbox (
768770 openshell_pb2 .CreateSandboxRequest (
771+ workspace_scope = _workspace_scope (workspace ),
769772 spec = request_spec ,
770773 name = name or "" ,
771774 labels = dict (labels ) if labels else {},
772- workspace_scope = _workspace_scope (workspace ),
773775 ),
774776 timeout = self ._timeout ,
775777 )
@@ -782,21 +784,21 @@ def create_from_template(
782784 self ,
783785 * ,
784786 workspace : str ,
785- template_name : str ,
787+ workload_template : str ,
786788 spec : openshell_pb2 .SandboxSpec | None = None ,
787789 name : str | None = None ,
788790 labels : Mapping [str , str ] | None = None ,
789791 ) -> SandboxRef :
790- if not template_name .strip ():
791- raise SandboxError ("template_name is required" )
792+ if not workload_template .strip ():
793+ raise SandboxError ("workload_template is required" )
792794 request_spec = spec if spec is not None else openshell_pb2 .SandboxSpec ()
793795 response = self ._stub .CreateSandbox (
794796 openshell_pb2 .CreateSandboxRequest (
797+ workspace_scope = _workspace_scope (workspace ),
795798 spec = request_spec ,
796799 name = name or "" ,
797800 labels = dict (labels ) if labels else {},
798- workspace_scope = _workspace_scope (workspace ),
799- workload_template_name = template_name ,
801+ workload_template = workload_template ,
800802 ),
801803 timeout = self ._timeout ,
802804 )
@@ -821,7 +823,7 @@ def create_session_from_template(
821823 self ,
822824 * ,
823825 workspace : str ,
824- template_name : str ,
826+ workload_template : str ,
825827 spec : openshell_pb2 .SandboxSpec | None = None ,
826828 name : str | None = None ,
827829 labels : Mapping [str , str ] | None = None ,
@@ -830,7 +832,7 @@ def create_session_from_template(
830832 self ,
831833 self .create_from_template (
832834 workspace = workspace ,
833- template_name = template_name ,
835+ workload_template = workload_template ,
834836 spec = spec ,
835837 name = name ,
836838 labels = labels ,
@@ -840,17 +842,18 @@ def create_session_from_template(
840842 def sandbox_templates (self ) -> SandboxTemplateClient :
841843 return SandboxTemplateClient (self ._channel , timeout = self ._timeout )
842844
843- def get (self , sandbox_name : str , * , workspace : str ) -> SandboxRef :
845+ def get (self , name : str , * , workspace : str ) -> SandboxRef :
844846 response = self ._stub .GetSandbox (
845847 openshell_pb2 .GetSandboxRequest (
846- name = sandbox_name , workspace_scope = _workspace_scope (workspace )
848+ workspace_scope = _workspace_scope (workspace ),
849+ name = name ,
847850 ),
848851 timeout = self ._timeout ,
849852 )
850853 return _sandbox_ref (response .sandbox )
851854
852- def get_session (self , sandbox_name : str , * , workspace : str ) -> SandboxSession :
853- return SandboxSession (self , self .get (sandbox_name , workspace = workspace ))
855+ def get_session (self , name : str , * , workspace : str ) -> SandboxSession :
856+ return SandboxSession (self , self .get (name , workspace = workspace ))
854857
855858 def list (
856859 self ,
@@ -960,12 +963,12 @@ def list_ids_for_all_workspaces(
960963 ]
961964
962965 def delete (
963- self , sandbox_name : str , * , workspace : str , allow_missing : bool = False
966+ self , name : str , * , workspace : str , allow_missing : bool = False
964967 ) -> DeletionResult :
965968 response = self ._stub .DeleteSandbox (
966969 openshell_pb2 .DeleteSandboxRequest (
967- name = sandbox_name ,
968970 workspace_scope = _workspace_scope (workspace ),
971+ name = name ,
969972 allow_missing = allow_missing ,
970973 ),
971974 timeout = self ._timeout ,
@@ -974,27 +977,29 @@ def delete(
974977 DeletionOutcome (response .outcome ), response .sandbox_id or None
975978 )
976979
977- def stop (self , sandbox_name : str , * , workspace : str ) -> SandboxRef :
980+ def stop (self , name : str , * , workspace : str ) -> SandboxRef :
978981 response = self ._stub .StopSandbox (
979982 openshell_pb2 .StopSandboxRequest (
980- name = sandbox_name , workspace_scope = _workspace_scope (workspace )
983+ workspace_scope = _workspace_scope (workspace ),
984+ name = name ,
981985 ),
982986 timeout = self ._timeout ,
983987 )
984988 return _sandbox_ref (response .sandbox )
985989
986- def start (self , sandbox_name : str , * , workspace : str ) -> SandboxRef :
990+ def start (self , name : str , * , workspace : str ) -> SandboxRef :
987991 response = self ._stub .StartSandbox (
988992 openshell_pb2 .StartSandboxRequest (
989- name = sandbox_name , workspace_scope = _workspace_scope (workspace )
993+ workspace_scope = _workspace_scope (workspace ),
994+ name = name ,
990995 ),
991996 timeout = self ._timeout ,
992997 )
993998 return _sandbox_ref (response .sandbox )
994999
9951000 def wait_deleted (
9961001 self ,
997- sandbox_name : str ,
1002+ name : str ,
9981003 * ,
9991004 workspace : str ,
10001005 timeout_seconds : float = 60.0 ,
@@ -1003,7 +1008,7 @@ def wait_deleted(
10031008 deadline = time .time () + timeout_seconds
10041009 while time .time () < deadline :
10051010 try :
1006- current = self .get (sandbox_name , workspace = workspace )
1011+ current = self .get (name , workspace = workspace )
10071012 if (
10081013 expected_sandbox_id is not None
10091014 and current .id != expected_sandbox_id
@@ -1014,24 +1019,24 @@ def wait_deleted(
10141019 return
10151020 raise
10161021 time .sleep (1 )
1017- raise SandboxError (f"sandbox { sandbox_name } was not deleted within timeout" )
1022+ raise SandboxError (f"sandbox { name } was not deleted within timeout" )
10181023
10191024 def wait_ready (
1020- self , sandbox_name : str , * , workspace : str , timeout_seconds : float = 300.0
1025+ self , name : str , * , workspace : str , timeout_seconds : float = 300.0
10211026 ) -> SandboxRef :
10221027 return self ._wait_for_phase (
1023- sandbox_name ,
1028+ name ,
10241029 workspace = workspace ,
10251030 target_phase = openshell_pb2 .SANDBOX_PHASE_READY ,
10261031 target_name = "ready" ,
10271032 timeout_seconds = timeout_seconds ,
10281033 )
10291034
10301035 def wait_stopped (
1031- self , sandbox_name : str , * , workspace : str , timeout_seconds : float = 300.0
1036+ self , name : str , * , workspace : str , timeout_seconds : float = 300.0
10321037 ) -> SandboxRef :
10331038 return self ._wait_for_phase (
1034- sandbox_name ,
1039+ name ,
10351040 workspace = workspace ,
10361041 target_phase = openshell_pb2 .SANDBOX_PHASE_STOPPED ,
10371042 target_name = "stopped" ,
@@ -1040,7 +1045,7 @@ def wait_stopped(
10401045
10411046 def _wait_for_phase (
10421047 self ,
1043- sandbox_name : str ,
1048+ name : str ,
10441049 * ,
10451050 workspace : str ,
10461051 target_phase : int ,
@@ -1049,7 +1054,7 @@ def _wait_for_phase(
10491054 ) -> SandboxRef :
10501055 deadline = time .time () + timeout_seconds
10511056 while time .time () < deadline :
1052- sandbox = self .get (sandbox_name , workspace = workspace )
1057+ sandbox = self .get (name , workspace = workspace )
10531058 if sandbox .status .phase == target_phase :
10541059 return sandbox
10551060 if (
@@ -1061,21 +1066,18 @@ def _wait_for_phase(
10611066 target_phase == openshell_pb2 .SANDBOX_PHASE_READY
10621067 and sandbox .status .phase == openshell_pb2 .SANDBOX_PHASE_STOPPED
10631068 ):
1064- raise SandboxError (
1065- f"sandbox { sandbox_name } stopped before becoming ready"
1066- )
1069+ raise SandboxError (f"sandbox { name } stopped before becoming ready" )
10671070 if sandbox .status .phase == openshell_pb2 .SANDBOX_PHASE_ERROR :
1068- raise SandboxError (f"sandbox { sandbox_name } entered error phase" )
1071+ raise SandboxError (f"sandbox { name } entered error phase" )
10691072 time .sleep (1 )
1070- raise SandboxError (
1071- f"sandbox { sandbox_name } was not { target_name } within timeout"
1072- )
1073+ raise SandboxError (f"sandbox { name } was not { target_name } within timeout" )
10731074
10741075 def exec_stream (
10751076 self ,
1076- sandbox_id : str ,
1077+ sandbox : str ,
10771078 command : Sequence [str ],
10781079 * ,
1080+ workspace : str ,
10791081 workdir : str | None = None ,
10801082 env : Mapping [str , str ] | None = None ,
10811083 stdin : bytes | None = None ,
@@ -1086,7 +1088,8 @@ def exec_stream(
10861088 raise SandboxError ("command must not be empty" )
10871089
10881090 request = openshell_pb2 .ExecSandboxRequest (
1089- sandbox_id = sandbox_id ,
1091+ workspace_scope = _workspace_scope (workspace ),
1092+ sandbox = sandbox ,
10901093 command = list (command ),
10911094 workdir = workdir or "" ,
10921095 environment = dict (env or {}),
@@ -1130,9 +1133,10 @@ def exec_stream(
11301133
11311134 def exec (
11321135 self ,
1133- sandbox_id : str ,
1136+ sandbox : str ,
11341137 command : Sequence [str ],
11351138 * ,
1139+ workspace : str ,
11361140 stream_output : bool = False ,
11371141 workdir : str | None = None ,
11381142 env : Mapping [str , str ] | None = None ,
@@ -1142,8 +1146,9 @@ def exec(
11421146 ) -> ExecResult :
11431147 result : ExecResult | None = None
11441148 for item in self .exec_stream (
1145- sandbox_id ,
1149+ sandbox ,
11461150 command ,
1151+ workspace = workspace ,
11471152 workdir = workdir ,
11481153 env = env ,
11491154 stdin = stdin ,
@@ -1165,9 +1170,10 @@ def exec(
11651170
11661171 def exec_python (
11671172 self ,
1168- sandbox_id : str ,
1173+ sandbox : str ,
11691174 function : Callable [..., object ],
11701175 * ,
1176+ workspace : str ,
11711177 args : Sequence [object ] = (),
11721178 kwargs : Mapping [str , object ] | None = None ,
11731179 stream_output : bool = False ,
@@ -1182,8 +1188,9 @@ def exec_python(
11821188 kwargs = kwargs ,
11831189 )
11841190 return self .exec (
1185- sandbox_id ,
1191+ sandbox ,
11861192 [_SANDBOX_PYTHON_BIN , "-c" , _PYTHON_CLOUDPICKLE_BOOTSTRAP ],
1193+ workspace = workspace ,
11871194 stream_output = stream_output ,
11881195 workdir = workdir ,
11891196 env = exec_env ,
@@ -1262,7 +1269,7 @@ def get(
12621269 ) -> openshell_pb2 .SandboxWorkloadTemplate :
12631270 response = self ._stub .GetSandboxTemplate (
12641271 openshell_pb2 .GetSandboxTemplateRequest (
1265- name = name , workspace_scope = _workspace_scope (workspace )
1272+ workspace_scope = _workspace_scope (workspace ), name = name
12661273 ),
12671274 timeout = self ._timeout ,
12681275 )
@@ -1350,8 +1357,8 @@ def delete(
13501357 ) -> DeletionResult :
13511358 response = self ._stub .DeleteSandboxTemplate (
13521359 openshell_pb2 .DeleteSandboxTemplateRequest (
1353- name = name ,
13541360 workspace_scope = _workspace_scope (workspace ),
1361+ name = name ,
13551362 allow_missing = allow_missing ,
13561363 ),
13571364 timeout = self ._timeout ,
@@ -1467,7 +1474,7 @@ def __init__(
14671474 spec : openshell_pb2 .SandboxSpec | None = None ,
14681475 name : str | None = None ,
14691476 labels : Mapping [str , str ] | None = None ,
1470- template_name : str | None = None ,
1477+ workload_template : str | None = None ,
14711478 timeout : float = 30.0 ,
14721479 ready_timeout_seconds : float = 120.0 ,
14731480 auto_refresh : bool = True ,
@@ -1493,7 +1500,7 @@ def __init__(
14931500 self ._name = name
14941501 # Copy so later caller mutation cannot change what gets sent on enter.
14951502 self ._labels = dict (labels ) if labels is not None else None
1496- self ._template_name = template_name
1503+ self ._workload_template = workload_template
14971504 self ._timeout = timeout
14981505 self ._ready_timeout_seconds = ready_timeout_seconds
14991506 self ._auto_refresh = auto_refresh
@@ -1521,10 +1528,10 @@ def __enter__(self) -> Sandbox:
15211528 if self ._sandbox_input is not None and (
15221529 self ._name is not None
15231530 or self ._labels is not None
1524- or self ._template_name is not None
1531+ or self ._workload_template is not None
15251532 ):
15261533 raise SandboxError (
1527- "name, labels, and template_name cannot be set when attaching to an existing sandbox"
1534+ "name, labels, and workload_template cannot be set when attaching to an existing sandbox"
15281535 )
15291536
15301537 client = SandboxClient .from_active_cluster (
@@ -1537,10 +1544,10 @@ def __enter__(self) -> Sandbox:
15371544 )
15381545 self ._client = client
15391546
1540- if self ._sandbox_input is None and self ._template_name is not None :
1547+ if self ._sandbox_input is None and self ._workload_template is not None :
15411548 self ._session = client .create_session_from_template (
15421549 workspace = self ._workspace ,
1543- template_name = self ._template_name ,
1550+ workload_template = self ._workload_template ,
15441551 spec = self ._spec ,
15451552 name = self ._name ,
15461553 labels = self ._labels ,
0 commit comments