Skip to content

Public API client

Access this client through sandbox.api. It uses the API token from SandboxKey. Methods inherited from the storage, analysis, scanning, and maintenance mixins are listed below.

ptsandbox.sandbox.api.SandboxApi

Bases: StorageMixin, AnalysisMixin, ScanMixin, MaintenanceMixin

Using raw queries to sandbox API

close async

close() -> None

Close the underlying aiohttp session.

get_images async

get_images() -> SandboxGetImagesResponse

Get a list of available images in the sandbox

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

get_health_status async

get_health_status() -> SandboxGetHealthStatusResponse

Checking the API status

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

get_version async

get_version() -> SandboxGetVersionResponse

Get information about the product

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

source_check_file async

source_check_file(file: str | Path | bytes | BinaryIO, data: SandboxScanWithSourceFileRequest, read_timeout: int = 240) -> SandboxBaseTaskResponse

Send a file to the sandbox with source settings

Parameters:

  • file (str | Path | bytes | BinaryIO) –

    The file to be sent for analysis

  • data (SandboxScanWithSourceFileRequest) –

    Request parameters in model

  • read_timeout (int, default: 240 ) –

    Response waiting time in seconds

Raises:

  • SandboxException –

    if incorrect arguments are passed (usually when ignoring type hints)

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

source_check_url async

source_check_url(data: SandboxScanWithSourceURLRequest, read_timeout: int = 240) -> SandboxBaseTaskResponse

Send the URL to the sandbox with source settings

Parameters:

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

source_get_status async

source_get_status(data: SandboxCheckTaskRequest) -> SandboxCheckTaskResponse

Check the status of a scan started via the source API (source_check_file / source_check_url).

Returns only the status without the full report. For the full report, use source_get_report.

Parameters:

Returns:

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

source_get_report async

source_get_report(scan_id: UUID) -> SandboxBaseTaskResponse

Get the full scan report created using the source settings

Parameters:

  • scan_id (UUID) –

    task id

Returns:

  • SandboxBaseTaskResponse –

    The response from the sandbox is either with partial information (when using async_result), or with full information.

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

create_scan async

create_scan(data: SandboxScanTaskRequest, read_timeout: int = 0) -> SandboxBaseTaskResponse

Send the specified file to the sandbox for analysis

Parameters:

  • data (SandboxScanTaskRequest) –

    sandbox parameters in model

  • read_timeout (int, default: 0 ) –

    response waiting time in seconds

Returns:

  • SandboxBaseTaskResponse –

    The response from the sandbox is either with partial information (when using async_result), or with full information.

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

create_advanced_scan async

create_advanced_scan(data: SandboxAdvancedScanTaskRequest, read_timeout: int = 0) -> SandboxBaseTaskResponse

Send the specified file to the sandbox for analysis using advanced API

Parameters:

Returns:

  • SandboxBaseTaskResponse –

    The response from the sandbox is either with partial information (when using async_result), or with full information.

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

create_url_scan async

create_url_scan(data: SandboxScanURLTaskRequest, read_timeout: int = 0) -> SandboxBaseTaskResponse

Send the URL to the sandbox

Parameters:

  • data (SandboxScanURLTaskRequest) –

    sandbox parameters in model

  • read_timeout (int, default: 0 ) –

    response waiting time in seconds

Returns:

  • SandboxBaseTaskResponse –

    The response from the sandbox is either with partial information (when using async_result), or with full information.

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

check_task async

check_task(data: SandboxCheckTaskRequest) -> SandboxCheckTaskResponse

Checking the result of a scan running with the async_result flag

Parameters:

Returns:

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

get_report async

get_report(scan_id: UUID) -> SandboxBaseTaskResponse

Getting the full task scan report

Parameters:

  • scan_id (UUID) –

    ID of the task to get the report for

Returns:

  • SandboxBaseTaskResponse –

    The response from the sandbox is either with partial information (when using async_result), or with full information.

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

create_rescan async

create_rescan(data: SandboxRescanTaskRequest, read_timeout: int = 300) -> SandboxBaseTaskResponse

Run a retro scan to check for detects without running a behavioral analysis.

Parameters:

  • data (SandboxRescanTaskRequest) –

    sandbox parameters in model

  • read_timeout (int, default: 300 ) –

    response waiting time in seconds

Returns:

  • SandboxBaseTaskResponse –

    The response from the sandbox is either with partial information (when using async_result), or with full information.

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

get_email_headers async

get_email_headers(data: str | Path | bytes | BinaryIO) -> AsyncIterator[bytes]

Upload an email to receive headers

Parameters:

  • data (str | Path | bytes | BinaryIO) –

    path to .eml file, its content or a binary stream

Returns:

  • AsyncIterator[bytes] –

    The header file

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

get_tasks async

get_tasks(data: dict[str, Any]) -> SandboxTasksResponse

Get tasks listing

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

upload_file async

upload_file(file: str | Path | bytes | BinaryIO, upload_timeout: float = 300) -> SandboxUploadScanFileResponse

Uploads the file to the sandbox

Parameters:

  • file (str | Path | bytes | BinaryIO) –

    a path in the form of a string, either a Path object or binary data

  • upload_timeout (float, default: 300 ) –

    if a large enough file is being uploaded, increase timeout (in seconds).

Returns:

  • SandboxUploadScanFileResponse –

    The link to the file in the temporary storage and the lifetime of this file are returned, or an exception is thrown.

Raises:

  • SandboxException –

    if incorrect arguments are passed (usually when ignoring type hints)

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

  • ValidationError –

    if the response body does not match the expected model

download_artifact async

download_artifact(file_uri: str, read_timeout: int = 120) -> bytes

Download file from the sandbox by hash

Parameters:

  • file_uri (str) –

    Permanent file identifier in the sha256:<sha256_hex> format.

    This is not the same as the temporary file_uri returned by :meth:upload_file (sfm:stream_v1...), which is only valid for use with scan creation endpoints.

  • read_timeout (int, default: 120 ) –

    response waiting time in seconds

Returns:

  • bytes –

    File data

Raises:

  • ClientResponseError –

    if the server returns an error status (404 if the file is not found)

  • ClientError –

    on connection or transport errors

download_artifact_stream async

download_artifact_stream(file_uri: str, read_timeout: int = 120) -> AsyncIterator[bytes]

Download file from the sandbox by hash

Parameters:

  • file_uri (str) –

    Permanent file identifier in the sha256:<sha256_hex> format.

    This is not the same as the temporary file_uri returned by :meth:upload_file (sfm:stream_v1...), which is only valid for use with scan creation endpoints.

  • read_timeout (int, default: 120 ) –

    response waiting time in seconds

Returns:

  • AsyncIterator[bytes] –

    streaming file data

Raises:

  • ClientResponseError –

    if the server returns an error status (404 if the file is not found)

  • ClientError –

    on connection or transport errors