
    =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)z?Sandbox class for interacting with a specific sandbox instance.    )annotations)	dataclassfield)TYPE_CHECKINGAnyOptionalUnionN)DataplaneNotConfiguredErrorResourceNotFoundErrorSandboxConnectionError)handle_sandbox_http_error)ExecutionResult)SandboxClientc                  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)'Sandbox   a3  Represents an active sandbox for running commands and file operations.

This class is typically obtained from SandboxClient.sandbox() and supports
the 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:
    with client.sandbox(template_name="python-sandbox") as sandbox:
        result = 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$ )	zCreate a Sandbox from API response dict.

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

Returns:
    Sandbox instance.
r    r   r   r   r   r   )r   r   r   r   r   r   r   r   )get)clsdataclientauto_deletes       \/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langsmith/sandbox/_sandbox.py	from_dictSandbox.from_dict8   sb    " &"%((?B7((?3xx~xx-xx-$	
 		
    c                    U $ )zEnter context manager. selfs    r'   	__enter__Sandbox.__enter__T   s    r*   c                    U R                   (       a'   U R                  R                  U R                  5        gg! [         a     gf = f)z6Exit context manager, optionally deleting the sandbox.N)r   r   delete_sandboxr   	Exception)r.   exc_typeexc_valexc_tbs       r'   __exit__Sandbox.__exit__X   sA     ++DII6   s   %: 
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Sandbox._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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$ ! [        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)a  Execute a command in the sandbox.

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Sandbox.runv   s   8 335x(#

 ? EN? EN	||))..s'TV,.WH%%'==?D"xx"-xx"-((;3 
 !! 	(03qcB $$ 	%a(	s$   BB- -DCD4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nUR                  5         g! [        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)	a  Write content to a file in the sandbox.

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=   rI   rJ   N)r:   
isinstancer   encoder   rK   rL   rM   rN   rO   r   r   rP   r   )	r.   rY   contentr=   r   rQ   r[   rS   rT   s	            r'   writeSandbox.write   s    * 335w' gs##nnW-G&'*+
	)||))..VTN% / H %%'!! 	(03qcB $$ 	)%a((	)s$   7A; ;CB++CCCc                  U R                  5       nU S3n U R                  R                  R                  USU0US9nUR	                  5         UR
                  $ ! [        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)aJ  Read a file from the sandbox.

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=   rI   rJ   Ni  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Sandbox.read   s    & 335y)	||))--VTNG . H %%'###!! 	(03qcB $$ 	zz%%,+TF":499+QG"(  &a(	s%   AA C(.B

C(!AC##C(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      s`   * I#'M='B $J$ $J$ #t<G]<E48L$8
 !	

 
 	

 

 
6  ) 	
 
"( (,! 88 	8
 &8 8 8 
8~ ()() #()
 () 
()T 13 ( (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._clientr   r   r,   r*   r'   <module>rz      sL    E " ( 6 6  
 A 57 k k kr*   