
    =Ki#                        S r SSKJr  SSKJrJr  SSKJrJrJ	r	J
r
  SSKrSSKJrJrJr  SSKJr  SSKJr  \(       a  SS	KJr  \ " S
 S5      5       rg)z0AsyncSandbox class for async sandbox operations.    )annotations)	dataclassfield)TYPE_CHECKINGAnyOptionalUnionN)DataplaneNotConfiguredErrorResourceNotFoundErrorSandboxConnectionError)handle_sandbox_http_error)ExecutionResult)AsyncSandboxClientc                  L   \ rS rSr% SrS\S'   S\S'   SrS\S'   SrS\S	'   SrS\S
'   Sr	S\S'   \
" SSS9rS\S'   \
" SSS9rS\S'   \ S       S S jj5       rS!S jr        S"S jrS#S jrSSSSS.           S$S jjrSS.       S%S jjrSS.S&S jjrSrg)'AsyncSandbox   aV  Represents an active sandbox for running commands and file operations async.

This class is typically obtained from AsyncSandboxClient.sandbox() and supports
the async context manager protocol for automatic cleanup.

Attributes:
    name: Display name (can be updated).
    template_name: Name of the template used to create this sandbox.
    dataplane_url: URL for data plane operations (file I/O, command execution).
    id: Unique identifier (UUID). Remains constant even if name changes.
        May be None for resources created before ID support was added.
    created_at: Timestamp when the sandbox was created.
    updated_at: Timestamp when the sandbox was last updated.

Example:
    async with await client.sandbox(template_name="python-sandbox") as sandbox:
        result = await sandbox.run("python --version")
        print(result.stdout)
strnametemplate_nameNOptional[str]dataplane_urlid
created_at
updated_atF)reprdefaultr   _clientTbool_auto_deletec                    U " UR                  SS5      UR                  SS5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UUS9$ )	a  Create an AsyncSandbox from API response dict.

Args:
    data: API response dictionary containing sandbox data.
    client: Parent AsyncSandboxClient for operations.
    auto_delete: Whether to delete the sandbox on context exit.

Returns:
    AsyncSandbox instance.
r    r   r   r   r   r   )r   r   r   r   r   r   r   r   )get)clsdataclientauto_deletes       b/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langsmith/sandbox/_async_sandbox.py	from_dictAsyncSandbox.from_dict8   sb    " &"%((?B7((?3xx~xx-xx-$	
 		
    c                   #    U $ 7f)zEnter async context manager. selfs    r'   
__aenter__AsyncSandbox.__aenter__T   s
     s   c                   #    U R                   (       a/   U R                  R                  U R                  5      I Sh  vN   gg N! [         a     gf = f7f)z<Exit async context manager, optionally deleting the sandbox.N)r   r   delete_sandboxr   	Exception)r.   exc_typeexc_valexc_tbs       r'   	__aexit__AsyncSandbox.__aexit__X   sJ      ll11$))<<< < s8   A(A AA AA 
AAAAc                n    U R                   (       d  [        SU R                   S35      eU R                   $ )zValidate and return the dataplane URL.

Returns:
    The dataplane URL.

Raises:
    DataplaneNotConfiguredError: If dataplane_url is not configured.
z	Sandbox 'zW' does not have a dataplane_url configured. Runtime operations require a dataplane URL.)r   r
   r   r-   s    r'   _require_dataplane_url#AsyncSandbox._require_dataplane_urlf   s=     !!-DII; '> >  !!!r*   <   z	/bin/bash)timeoutenvcwdshellc               ,  #    U R                  5       nU S3nUUUS.nUb  X8S'   Ub  XHS'    U R                  R                  R                  XxUS-   S9I Sh  vN n	U	R	                  5         U	R                  5       n
[        U
R                  SS	5      U
R                  S
S	5      U
R                  SS5      S9$  N_! [        R                   a!  n[        SU R                   SU 35      UeSnAf[        R                   a  n[        U5        e SnAff = f7f)a  Execute a command in the sandbox asynchronously.

Args:
    command: Shell command to execute.
    timeout: Command timeout in seconds.
    env: Environment variables to set for the command.
    cwd: Working directory for command execution. If None, uses sandbox default.
    shell: Shell to use for command execution. Defaults to "/bin/bash".

Returns:
    ExecutionResult with stdout, stderr, and exit_code.

Raises:
    DataplaneNotConfiguredError: If dataplane_url is not configured.
    SandboxOperationError: If command execution fails.
    SandboxConnectionError: If connection to sandbox fails.
    SandboxNotReadyError: If sandbox is not ready.
    SandboxClientError: For other errors.
z/execute)commandr=   r@   Nr>   r?   
   )jsonr=   stdoutr!   stderr	exit_code)rE   rF   rG   Failed to connect to sandbox '': )r:   r   _httppostraise_for_statusrD   r   r"   httpxConnectErrorr   r   HTTPStatusErrorr   )r.   rB   r=   r>   r?   r@   r   urlpayloadresponser$   es               r'   runAsyncSandbox.runv   s)    8 335x(#

 ? EN? EN	!\\//447R< 5  H %%'==?D"xx"-xx"-((;3  !! 	(03qcB $$ 	%a(	sG   *D*B9 B7AB9 6D7B9 9DC))D DDD)r=   c                 #    U R                  5       nU S3n[        U[        5      (       a  UR                  S5      nSSU40n U R                  R
                  R                  USU0XcS9I Sh  vN nUR                  5         g N! [        R                   a!  n[        SU R                   SU 35      UeSnAf[        R                   a  n[        U5         SnAgSnAff = f7f)	a  Write content to a file in the sandbox asynchronously.

Args:
    path: Target file path in the sandbox.
    content: File content (str or bytes).
    timeout: Request timeout in seconds.

Raises:
    DataplaneNotConfiguredError: If dataplane_url is not configured.
    SandboxOperationError: If file write fails.
    SandboxConnectionError: If connection to sandbox fails.
    SandboxNotReadyError: If sandbox is not ready.
    SandboxClientError: For other errors.
z/uploadzutf-8filepath)paramsfilesr=   NrI   rJ   )r:   
isinstancer   encoder   rK   rL   rM   rN   rO   r   r   rP   r   )	r.   rY   contentr=   r   rQ   r[   rS   rT   s	            r'   writeAsyncSandbox.write   s     * 335w' gs##nnW-G&'*+
	)!\\//44VTN% 5  H %%' !! 	(03qcB $$ 	)%a((	)sN   AC&*B /B0B C&B C#B77C#CC&C##C&c                 #    U R                  5       nU S3n U R                  R                  R                  USU0US9I Sh  vN nUR	                  5         UR
                  $  N ! [        R                   a!  n[        SU R                   SU 35      UeSnAf[        R                   aG  nUR                  R                  S:X  a  [        SU S	U R                   S
3SS9Ue[        U5        e SnAff = f7f)aY  Read a file from the sandbox asynchronously.

Args:
    path: File path to read. Supports both absolute paths (e.g., /tmp/file.txt)
          and relative paths (resolved from /home/user/).
    timeout: Request timeout in seconds.

Returns:
    File contents as bytes.

Raises:
    DataplaneNotConfiguredError: If dataplane_url is not configured.
    ResourceNotFoundError: If the file doesn't exist.
    SandboxOperationError: If file read fails.
    SandboxConnectionError: If connection to sandbox fails.
    SandboxNotReadyError: If sandbox is not ready.
    SandboxClientError: For other errors.
z	/downloadrY   )rZ   r=   NrI   rJ   i  zFile 'z' not found in sandbox ''rX   )resource_type)r:   r   rK   r"   rM   r^   rN   rO   r   r   rP   rS   status_coder   r   )r.   rY   r=   r   rQ   rS   rT   s          r'   readAsyncSandbox.read   s    & 335y)	!\\//33VTNG 4  H %%'###	
 !! 	(03qcB $$ 	zz%%,+TF":499+QG"(  &a(	sG   C7*A& A$A& #C7$A& &C4:BC4-AC//C44C7r,   )T)r$   zdict[str, Any]r%   r   r&   r   returnr   )rg   r   )r4   zOptional[type]r5   zOptional[BaseException]r6   zOptional[Any]rg   None)rg   r   )rB   r   r=   intr>   zOptional[dict[str, str]]r?   r   r@   r   rg   r   )rY   r   r^   zUnion[str, bytes]r=   ri   rg   rh   )rY   r   r=   ri   rg   bytes)__name__
__module____qualname____firstlineno____doc____annotations__r   r   r   r   r   r   r   classmethodr(   r/   r7   r:   rU   r_   re   __static_attributes__r,   r*   r'   r   r      sa   * I#'M='B $J$ $J$ #(UD"AGAE48L$8
 !	

 #
 	

 

 
6  ) 	
 
"( (,! :: 	:
 &: : : 
:B ()() #()
 () 
()T 79 ( (r*   r   )ro   
__future__r   dataclassesr   r   typingr   r   r   r	   rN   langsmith.sandbox._exceptionsr
   r   r   langsmith.sandbox._helpersr   langsmith.sandbox._modelsr   langsmith.sandbox._async_clientr   r   r,   r*   r'   <module>rz      sL    6 " ( 6 6  
 A 5B m m mr*   