+
    PjG                     X   R t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	t	^ RI
HtHtHtHtHtHtHtHtHtHtHtHt ^ RIHt ^ RIHtHt ^RIHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t& ^RI'H(t(H)t) ^R	I*H+t+ ^R
I,H-t-H.t. ]&! RR7      t/]&! RR7      t0]/Pc                  ]0RR7       ]&! RR7      t2]/Pc                  ]2RR7       ]]3](! RR7      3,          t4]R R l4       t5]/Pm                  R. RBOR7      RCR R ll4       t7]/Pm                  RRR/RR.R7      RDR R  ll4       t8]/Pm                  R!RR/R"R#.R7      RER$ R% ll4       t9]/Pm                  R&R'R(.R7      RFR) R* ll4       t:]/Pm                  R+. RGOR7      RHR, R- ll4       t;]0Pm                  R. RIOR7      RR]RRRR3R. R/ ll4       t<]0Pm                  R0R1.R7      RFR2 R3 ll4       t=]0Pm                  R4R5.R7      RJR6 R7 ll4       t>R8 R9 lt?R: R; lt@]2Pm                  R0R<.R7      RFR= R> ll4       tA]2Pm                  R+R?.R7      RFR@ RA ll4       tBR# )KzCContains commands to run and manage sandboxes on Hugging Face Jobs.N)contextmanager)	AnnotatedAnyIterator)DEFAULT_IDLE_TIMEOUTDEFAULT_IMAGEDEFAULT_SANDBOXES_PER_HOST
MODE_LABEL	MODE_POOL
POOL_LABELSANDBOX_LABELSHARED_ID_SEPSandboxSandboxPoolSandboxProcess_split_sandbox_id)delete_pool_cache)CLIErrorSandboxError)

EnvFileOptEnvOptSecretsFileOpt
SecretsOptTokenOpt
VolumesOpt
get_hf_apiparse_env_mapparse_volumestyper_factory)ArgumentOption)out)	FlavorOptNamespaceOptz.Run and manage sandboxes on Hugging Face Jobs.helpzBWarm pools of host VMs and spawn cheap shared sandboxes from them.pool)namez8List and stop background processes running in a sandbox.processz1The sandbox id as printed by `hf sandbox create`.c          	      z    V ^8  d   QhR\         R\         R,          R\         R,          R\        \        ,          /# )   
sandbox_id	namespaceNtokenreturn)strr   r   )formats   "t/Users/ahmed/devFolder/Ultron/claude-voice/gateway/.venv/lib/python3.14/site-packages/huggingface_hub/cli/sandbox.py__annotate__r2   C   s6       C$J sTz hW^N_     c             #     "   \         P                  ! WVR7      p Vx  VP                  4        R#   TP                  4        i ; i5i)zIReattach to a sandbox and close the HTTP client when the command is done.r,   r-   N)r   connectclose)r+   r,   r-   sandboxs   &$$ r1   _connectr9   B   s3      oojUKGs   A2 AAAcreate)examplesc                   V ^8  d   QhR\         \        R,          \        RR7      3,          R\         \        R,          \        RRR7      3,          R\        R	\         \        R,          \        R
R7      3,          R\
        R\        R\        R\        R\        R\        R\         \        \        RRR7      3,          R\        RR/# )r*   imageNzDocker image (needs /bin/sh).r$   r&   z--poolzJSpawn a cheap shared sandbox in this pool (from `hf sandbox pool create`).flavoridle_timeoutzTAuto-terminate the sandbox after this much inactivity (e.g. '10m'). Defaults to 10m.envsecretsenv_filesecrets_filevolumer,   forward_hf_tokenz--forward-hf-tokenz0Inject your HF token as HF_TOKEN in the sandbox.r-   r.   )r   r/   r   r    r"   r   r   r   r   r   r#   boolr   )r0   s   "r1   r2   r2   U   s     >C >CS4Z/N!OOP>C
d
xjk	m>C >C d
jk	m>C 
>C >C >C !>C >C  !>C"  f)0bcc#>C( )>C* 
+>Cr3   c                >   \         P                   ! 4       pVe   TM\        pVEe   V f   Vf	   V'       d   \        R4      hV'       g	   V'       d   \        R4      h\        P                  ! WVR7      P                  \        WF4      VV
R7      p\        P                  ! RVP                  VP                  V\         P                   ! 4       V,
          R R2R	7       \        P                  ! R
VP                   R24       \        P                  ! RVP                   R24       R# \        P
                  ! T ;'       g    \        T;'       g    RV\        WF4      \        WW4      \        V4      V	V
VR7	      pVP                  4        \        P                  ! RVP                  VP                   \         P                   ! 4       V,
          R R2R7       \        P                  ! R
VP                   R24       \        P                  ! RVP                   R24       R# )a~  Create a sandbox: a dedicated VM by default, or a cheap shared one with `--pool`.

Env and idle-timeout apply to the sandbox in both modes. With `--pool`, the image and
flavor come from the pool, so passing them here is an error; `--secrets` is also
rejected since pooled sandboxes have no encrypted-secrets channel (use `--env`). Define
a pool first with `hf sandbox pool create`.
NzQ--pool fixes the image/flavor (and volumes aren't supported); drop those options.zF--pool can't encrypt secrets; pass them with --env/--env-file instead.r5   )r@   r?   rE   zSandbox ready.1fs)idhostr&   elapsedz$Run a command with `hf sandbox exec z -- echo hello`.z#Terminate it with `hf sandbox kill `.	cpu-basic)	r=   r>   r?   r@   rA   volumesr,   rE   r-   )rJ   r=   rL   )timer   r   r   r6   r:   r   r!   resultrJ   host_idhintr   r   r   r7   r=   )r=   r&   r>   r?   r@   rA   rB   rC   rD   r,   rE   r-   startidlesbxr8   s   &&&&&&&&&&&&    r1   sandbox_createrW   L   s   L IIKE'3<9MD 2fnoolcdd!!$5IPPc,- Q 

 	

?svvCKKdW[W`W`WbejWjknVoopTqr7x?OPQ6svvhbABnn$$}$$#(g4f%)
G MMOJJ7::W]]tyy{]bObcfNgghLijHH3GJJ<?OPQHH27::,bABr3   execignore_unknown_optionsTz5hf sandbox exec <sandbox_id> -- python -c "print(42)"z1hf sandbox exec -w /app <sandbox_id> -- pytest -x)context_settingsr;   c                >   V ^8  d   QhR\         R\        \        \        ,          \	        RR7      3,          R\        \        R,          \        RRR	R7      3,          R
\        R\        R\        \        R,          \        RRR7      3,          R\        R\        RR/	# )r*   r+   commandzThe command to run.r$   workdirN-w	--workdirWorking directory.r@   rB   exec_timeoutz	--timeoutz)Kill the command after this many seconds.r,   r-   r.   )SandboxIdArgr   listr/   r   r    r   r   floatr#   r   )r0   s   "r1   r2   r2      s     (b (b(btCy(0E"FFG(b sTz6$BV#WWX(b 
	(b
 (b f[/Z[[(b (b (b 
(br3   c                4   R R lpR R lp	\        WVR7      ;_uu_ 4       p
V
P                  \        V4      \        W44      VVVV	RR7      pRRR4       XP                  '       dO   \
        P                  ! R	V R
24       \        P                  P                  VP                  ;'       g    ^|R7      hVP                  ^ 8w  d@   \        P                  P                  VP                  e   VP                  R7      h^R7      hR#   + '       g   i     L; i)zRun a command in a sandbox, streaming output. Exits with the command's exit code.

To start a long-running command in the background instead of waiting for it, use
`hf sandbox spawn`.
c                (    V ^8  d   QhR\         RR/# r*   datar.   Nr/   )r0   s   "r1   r2   "sandbox_exec.<locals>.__annotate__         3 4 r3   c                     \         P                  P                  V 4       \         P                  P                  4        R # N)sysstdoutwriteflushrh   s   &r1   write_stdout"sandbox_exec.<locals>.write_stdout   $    



r3   c                (    V ^8  d   QhR\         RR/# rg   ri   )r0   s   "r1   r2   rj      rk   r3   c                     \         P                  P                  V 4       \         P                  P                  4        R # rm   )rn   stderrrp   rq   rr   s   &r1   write_stderr"sandbox_exec.<locals>.write_stderr   ru   r3   r5   F)r@   cwdtimeout	on_stdout	on_stderrcheckNzCommand timed out after zs.)code)r9   runrc   r   	timed_outr!   errorclick
exceptionsExit	exit_code)r+   r\   r]   r@   rB   ra   r,   r-   rs   ry   r8   rQ   s   &&&&&&&&    r1   sandbox_execr      s    4 
*	?	?7Mc, ""  
 
@ 		,\N"=>##)9)9)@)@S#AA1##V=M=M=Y)9)9#aa_`#aa  
@	?s   +DD	spawnz;hf sandbox spawn <sandbox_id> -- python -m http.server 8000z8hf sandbox spawn -w /app <sandbox_id> -- uvicorn app:appc                    V ^8  d   QhR\         R\        \        \        ,          \	        RR7      3,          R\        \        R,          \        RRR	R7      3,          R
\        R\        R\        R\        RR/# )r*   r+   r\   z%The command to run in the background.r$   r]   Nr^   r_   r`   r@   rB   r,   r-   r.   )
rb   r   rc   r/   r   r    r   r   r#   r   )r0   s   "r1   r2   r2      s     T TTtCy(0W"XXYT sTz6$BV#WWXT 
	T
 T T T 
Tr3   c           	     ~   \        WVR7      ;_uu_ 4       pVP                  \        V4      \        W44      VRR7      pRRR4       \        P
                  ! RV XP                  R7       \        P                  ! RV  R24       \        P                  ! R	V  R
VP                   R24       R#   + '       g   i     Lv; i)zStart a long-running command in the background and return its pid (don't wait).

List a sandbox's processes with `hf sandbox process ls` and stop one with
`hf sandbox process kill`.
r5   T)r@   r{   
backgroundNzProcess startedr8   pidz+List processes with `hf sandbox process ls rM   z&Stop it with `hf sandbox process kill  )r9   r   rc   r   r!   rQ   r   rS   )	r+   r\   r]   r@   rB   r,   r-   r8   r(   s	   &&&&&&&  r1   sandbox_spawnr      s    , 
*	?	?7++d7ms1MSZgk+l 
@JJ *'++FHH::,bIJHH5j\7;;-rRS	 
@	?s   (B,,B<	cpz2hf sandbox cp data.csv <sandbox_id>:/data/data.csvz7hf sandbox cp <sandbox_id>:/app/result.json result.jsonc          
          V ^8  d   QhR\         \        \        RR7      3,          R\         \        \        RR7      3,          R\        R\        RR	/# )
r*   srcz,Source: a local path or <sandbox_id>:<path>.r$   dstz1Destination: a local path or <sandbox_id>:<path>.r,   r-   r.   N)r   r/   r   r#   r   )r0   s   "r1   r2   r2      sZ     + +	3&TUU	V+	3&YZZ	[+ + 	+
 
+r3   c                   R R lpV! V 4      w  rVV! V4      w  rxVRJ VRJ 8X  d   \        R4      hVe;   \        WRVR7      ;_uu_ 4       p	V	P                  P                  Wh4       RRR4       M?Vf   Q h\        WrVR7      ;_uu_ 4       p	V	P                  P	                  Wh4       RRR4       \
        P                  ! RWR7       R#   + '       g   i     L*; i  + '       g   i     L=; i)zCCopy a file between the local machine and a sandbox (docker-style).c                `    V ^8  d   QhR\         R\        \         R,          \         3,          /# )r*   refr.   N)r/   tuple)r0   s   "r1   r2    sandbox_cp.<locals>.__annotate__   s'      3 5tS1 r3   c                     R V 9   d?   V P                  R4      '       g(   V P                  R ^4      w  r\        V4      ^8  d   W3# RV 3# ):N)./~)
startswithsplitlen)r   r+   paths   &  r1   parsesandbox_cp.<locals>.parse   sK     #:cnn_=="yya0J:"!''Syr3   NzHExactly one of SRC and DST must be a sandbox path (<sandbox_id>:<path>).r5   Copied)r   r   )r   r9   filesdownloaduploadr!   rQ   )
r   r   r,   r-   r   src_sandboxsrc_pathdst_sandboxdst_pathr8   s
   &&&&      r1   
sandbox_cpr      s     "#JK!#JKt!45abbkeDDMM""86 ED &&&keDDMM  4 EJJxS* ED EDs   
C
CC	C+	killc                    V ^8  d   QhR\         \        R,          \        RR7      3,          R\         \        \	        RRR7      3,          R\         \        \	        R	R
RR7      3,          R\
        R\        RR/# )r*   r+   Nz$The sandbox or host id to terminate.r$   all_z--allz2Terminate every sandbox and host in the namespace.yes-y--yes$Answer Yes to prompts automatically.r,   r-   r.   r   r/   r   rF   r    r#   r   )r0   s   "r1   r2   r2     s~     /4 /4#*h4Z&[[\/4
D&/cdd
e/4 
4g4Z[[	\/4 	/4
 /4 
/4r3   c                n   \        VR7      pV'       d   \        VP                  RR.\        R/VR7      4      pV'       g   \        P
                  ! R4       R# \        P                  ! R\        V4       R	2VR
7       V F4  pVP                  VP                  VP                  P                  R7       K6  	  \        P                  ! R\        V4      R7       R# V f   \        R4      h\        W4      w  r\        V9   dJ    \!        WVR7      ;_uu_ 4       p
V
P#                  4        RRR4       \        P                  ! RT R7       R# VP)                  WR7      pVP*                  ;'       g    / P-                  \.        4      \0        8X  dh   \        P                  ! RV R2VR
7       VP                  VP                  VP                  P                  R7       \        P                  ! RVR7       R#  \!        WVR7      ;_uu_ 4       p
V
P#                  4        RRR4       \        P                  ! RT R7       R#   + '       g   i     EL; i  \$         d   p\        \'        T4      4      ThRp?ii ; i  + '       g   i     Lf; i  \$         d   p\        \'        T4      4      ThRp?ii ; i)z@Terminate a sandbox, a whole shared host, or everything (--all).r-   RUNNING
SCHEDULING1statuslabelsr,   zNo running sandboxes.N
Terminate zA sandbox job(s) (including shared hosts and all their sandboxes)?r   job_idr,   
Terminated)jobsz*Provide a sandbox id, a host id, or --all.r5   zSandbox terminated)rJ   zTerminate shared host z and all of its sandboxes?zHost terminated)r   rc   	list_jobsr   r!   textconfirmr   
cancel_jobrJ   ownerr'   rQ   r   r   r   r9   r   r   r/   inspect_jobr   getr	   r
   )r+   r   r   r,   r-   apir   jobsidnsr8   es   &&&&&       r1   sandbox_killr     s     5
!CCMM)\)BM[^K_ktMuvHH,-jT+lmsvwCNN#&&CIINNNC 

<c$i0CDD
6GC	**GG7 H 	

'J7 ///
3C

bj)Y6,SE1KLRUVcff		?

$-&jUCCwLLN D JJ#
3' HGG 	*3q6")	* DC &s1vA%&sl   I I *I 8J I<J  I	I I I9I44I9<J	J J J4J//J4c                j   V ^8  d   QhR\         \        R,          \        RR7      3,          R\        R\         \        \        R^R\         R	2R
7      3,          R\         \        R,          \        R^RR
7      3,          R\         \        R,          \        RR7      3,          R\        R\        RR/# )r*   r=   Nz+Docker image for the hosts (needs /bin/sh).r$   r>   per_hostz
--per-hostz&Sandboxes packed per host VM (default z).)minr%   	max_hostsz--max-hostsz'Optional cap on the number of host VMs.r?   zZShut a host down once it has had no sandboxes for this long (e.g. '10m'). Defaults to 10m.r,   r-   r.   )	r   r/   r   r"   intr    r   r#   r   )r0   s   "r1   r2   r2   O  s     (Z (ZS4Z/\!]]^(Z(Z |+QRlQmmo)pq	s(Z d
F=a6_``(Z d
pq	s(Z (Z (Z  
!(Zr3   c           
        \         P                   ! 4       pT ;'       g    \        p \        T T;'       g    RTTVe   TM\        VVR7      pVP                  p	VP
                  p
\        P                  ! RT	T T;'       g    RV
^ ,          \         P                   ! 4       V,
          R R2R7       \        P                  ! RV	 R	24       \        P                  ! R
V	 R	24       R# )zRWarm a pool: boot one host VM now, tagged so it can be found later by its pool id.rN   N)r=   r>   sandboxes_per_hostr   r?   r,   r-   zPool createdrH   rI   )rJ   r=   r>   rK   rL   z/Spawn a sandbox with `hf sandbox create --pool rM   z=Delete the pool (and its hosts) with `hf sandbox pool delete )	rP   r   r   r   r'   host_idsr!   rQ   rS   )r=   r>   r   r   r?   r,   r-   rT   r&   pool_idr   s   &&&&&&&    r1   pool_creater   G  s    4 IIKE""]E$$#%1%=\CWD iiG}}HJJ$$a[99;&s+1- HH>wirJKHHLWIUWXYr3   z	ls | listzhf sandbox pool lsc                4    V ^8  d   QhR\         R\        RR/# )r*   r,   r-   r.   N)r#   r   )r0   s   "r1   r2   r2   {  s+     J JJJ 
Jr3   c                   \        VR7      p/ pVP                  R\        \        /V R7       F  pVP                  ;'       g    / P                  \        4      pV'       g   K6  \        VP                  \        4      '       d   VP                  M/ pTP                  TRTRVP                  ;'       g    VP                  RVP                  RVP                  RR	4      R
^ /4      pVR
;;,          ^,          uu&   K  	  \        VP                  4       4      p\         P"                  ! VRR7       V'       g   \         P$                  ! R4       R# \         P$                  ! R4       R# )z9List running sandbox pools (grouped from their host VMs).r   r   r   rJ   r=   r>   r   SBX_CAPACITY hostsid_keyz)Create one with `hf sandbox pool create`.z5Spawn a sandbox with `hf sandbox create --pool <id>`.N)r   r   r	   r
   r   r   r   
isinstanceenvironmentdict
setdefaultdocker_imagespace_idr>   rc   valuesr!   tablerS   )	r,   r-   r   poolsr   r   r@   inforowss	   &&       r1   pool_lsr   z  s    5
!C')E}}Iz96MYb}czzR$$Z0!+COOT!B!Bcooc))99S\\#**CGGNB7	
 	W d  DIId4 <=HIr3   zdelete | rmz hf sandbox pool delete <pool_id>c                    V ^8  d   QhR\         \        \        RR7      3,          R\         \        \	        RRRR7      3,          R\
        R	\        R
R/# )r*   r   zPool id to delete.r$   r   r   r   r   r,   r-   r.   Nr   )r0   s   "r1   r2   r2     se     H HsH*>??@H	4g4Z[[	\H H 	H
 
Hr3   c           	        \        VR7      p\        VP                  RR.\        \        \
        V /VR7      4      pV'       g(   \        V 4       \        P                  ! RV  R24       R# \        P                  ! R\        V4       R	V  R
2VR7       V F4  pVP                  VP                  VP                  P                  R7       K6  	  \        V 4       \        P                  ! RV \        V4      R7       R# )zDTerminate every host VM of a pool (and therefore all its sandboxes).r   r   r   r   zNo running hosts for pool 'z'.Nr   z host(s) of pool 'z' (and all their sandboxes)?r   r   zPool deleted)rJ   hosts_terminated)r   rc   r   r	   r
   r   r   r!   r   r   r   r   rJ   r   r'   rQ   )r   r   r,   r-   r   r   r   s   &&&&   r1   pool_deleter     s     5
!C|,	:w? 	 	
E '".wir:;KK*SZL(:7)C_`fijcff		? gJJ~'CJGr3   c                \    V ^8  d   QhR\         \        \         ,          ,          R\         /# )r*   cmdr.   )r/   rc   )r0   s   "r1   r2   r2     s"     : :#S	/ :c :r3   c                 T    \        V \        4      '       d   V # R P                  V 4      # )r   )r   r/   join)r   s   &r1   _fmt_cmdr     s!    S#&&39CHHSM9r3   c                0    V ^8  d   QhR\         R\        /# )r*   r(   r.   )r   r/   )r0   s   "r1   r2   r2     s     V V VC Vr3   c                 j    V P                   '       d   R # V P                  f   R# RV P                   R2# )runningexitedzexited ())r   r   )r(   s   &r1   _fmt_statusr     s5    ((08UARAR@SST6UUr3   z"hf sandbox process ls <sandbox_id>c                @    V ^8  d   QhR\         R\        R\        RR/# )r*   r+   r,   r-   r.   N)rb   r#   r   )r0   s   "r1   r2   r2     s6     Q QQQ Q 
	Qr3   c                   \        WVR7      ;_uu_ 4       pVP                  4       pRRR4       X Uu. uF1  pRVP                  R\        V4      R\	        VP
                  4      /NK3  	  pp\        P                  ! VRR7       V'       g   \        P                  ! RV  R24       R# \        P                  ! R	V  R
24       R#   + '       g   i     L; iu upi )zUList the background processes running in a sandbox (started with `hf sandbox spawn`).r5   Nr   r   r   r   z!Start one with `hf sandbox spawn z -- <cmd>`.z'Stop one with `hf sandbox process kill z <pid>`.)	r9   	processesr   r   r   r   r!   r   rS   )r+   r,   r-   r8   r   pr   s   &&&    r1   
process_lsr    s     
*	?	?7%%'	 
@V_`V_QRUAEE8[^UHQUUOLV_D`IId5!4ZLLM::,hOP 
@	?`s   C7CC	z*hf sandbox process kill <sandbox_id> <pid>c          
      z    V ^8  d   QhR\         R\        \        \        RR7      3,          R\        R\
        RR/# )	r*   r+   r   z.The pid as printed by `hf sandbox process ls`.r$   r,   r-   r.   N)rb   r   r   r   r#   r   )r0   s   "r1   r2   r2     sJ     ? ??	3&VWW	X? ? 	?
 
?r3   c           	     0  a \        WVR7      ;_uu_ 4       p\        V3R lVP                  4        4       R4      pVf   \        RS RV  R24      hVP	                  4        RRR4       \
        P                  ! RV SR7       R#   + '       g   i     L+; i)	z/Stop a background process running in a sandbox.r5   c              3   L   <"   T F  qP                   S8X  g   K  Vx  K  	  R # 5irm   )r   ).0r   r   s   & r1   	<genexpr>process_kill.<locals>.<genexpr>  s     G#6a%%3,#6s   $
$NzNo process with pid z in sandbox r   zProcess stoppedr   )r9   nextr   r   r   r!   rQ   )r+   r   r,   r-   r8   r(   s   &f&&  r1   process_killr	    s{     
*	?	?7G7#4#4#6GN?1#l:,aPQQ	 
@
 JJ *#> 
@	?s   ABB	)zhf sandbox createzhf sandbox create ubuntu:24.04z%hf sandbox create --flavor a10g-smallz@hf sandbox create --pool pool-ab12cd34ef56 --env LOG_LEVEL=debug)NNNNNNNNNNFN)NNNNNN)NNNNN)NN)zhf sandbox kill <sandbox_id>zKhf sandbox kill <host_id>   # kills a whole shared host (all its sandboxes)zhf sandbox kill --all)NFFNN)zhf sandbox pool createz5hf sandbox pool create python:3.12 --flavor cpu-basicz7hf sandbox pool create --per-host 50 --idle-timeout 30m)FNN)C__doc__rn   rP   
contextlibr   typingr   r   r   r   huggingface_hub._sandboxr   r   r   r	   r
   r   r   r   r   r   r   r   huggingface_hub._sandbox_cacher   huggingface_hub.errorsr   r   
_cli_utilsr   r   r   r   r   r   r   r   r   r   
_frameworkr   r    _outputr!   r   r"   r#   sandbox_clipool_cli	add_groupprocess_clir/   rb   r9   r\   rW   r   r   r   r   r   r   r   r   r   r  r	   r3   r1   <module>r     s   J 
  % + +     = 9   )  ) !QRbc   hV  ,![\   k	  2h,_``a     >C>CB 
.5?;  (b(bV .5EB  TT* <A  ++@ 
  /4/4d 
   bf 	# 	 	"(Z(ZV 
+)=(>?J @J> 
01  H	H4:V [,P+QRQ SQ  V'S&TU? V?r3   