Skip to main content

langchain-daytona-data-analysis

This package provides the DaytonaDataAnalysisTool - LangChain tool integration that enables agents to perform secure Python data analysis in a sandboxed environment. It supports multi-step workflows, file uploads/downloads, and custom result handling, making it ideal for automating data analysis tasks with LangChain agents.

Installation

pip install -U langchain-daytona-data-analysis

You must configure credentials for Daytona. You can do this in one of three ways:

  1. Set the DAYTONA_API_KEY environment variable:

    export DAYTONA_API_KEY="your-daytona-api-key"
    
  2. Add it to a .env file in your project root:

    DAYTONA_API_KEY=your-daytona-api-key
    
  3. Pass the API key directly when instantiating DaytonaDataAnalysisTool:

    from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
    
    tool = DaytonaDataAnalysisTool(daytona_api_key="your-daytona-api-key")
    

Instantiation

Import and instantiate the tool:

from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
from daytona import ExecutionArtifacts

 # Optionally, you can pass an on_result callback.
 # This callback lets you apply custom logic to the data analysis result.
 # For example, you can save outputs, display charts, or trigger other actions.
def process_data_analysis_result(result: ExecutionArtifacts):
	print(result)

tool = DaytonaDataAnalysisTool(
	# daytona_api_key="your-daytona-api-key",  # Only needed if DAYTONA_API_KEY is not set as an environment variable
	# max_output_chars=20_000,  # Cap on printed output returned to the model (beginning and end are kept)
	on_result=process_data_analysis_result
)

Usage

The model only ever receives text: the code's printed output, plus a one-line summary of each generated chart (for example - scatter: Price vs. mileage). Chart image data stays out of the model's context; the full ExecutionArtifacts, PNG data included, are passed to on_result and attached to the returned ToolMessage as its artifact. Printed output longer than max_output_chars keeps its beginning and end.

DaytonaDataAnalysisTool can be used in three ways:

Direct Invocation with Args

tool.invoke({'data_analysis_python_code': "print('Hello World')"})
# 'Hello World'

Invocation with ToolCall

model_generated_tool_call = {
    "args": {'data_analysis_python_code': "print('Hello World')"},
    "id": "1",
    "name": tool.name,
    "type": "tool_call",
}

message = tool.invoke(model_generated_tool_call)
message.content   # 'Hello World'
message.artifact  # ExecutionArtifacts(stdout='Hello World\n', charts=[])

Usage Inside an Agent

from langchain.agents import create_agent
from langchain_anthropic import ChatAnthropic

model = ChatAnthropic(
    model_name="claude-haiku-4-5-20251001",
    temperature=0,
    max_tokens_to_sample=1024,
    timeout=None,
    max_retries=2,
    stop=None
)

agent = create_agent(model, tools=[tool])

API Reference

The following public methods are available on DaytonaDataAnalysisTool:

download_file(remote_path)

Downloads a file from the sandbox by its remote path.

  • remote_path: str — Path to the file in the sandbox.
  • Returns: bytes — File contents.

Example:

# Download a file from the sandbox
file_bytes = tool.download_file("/home/daytona/results.csv")

upload_file(file, description)

Uploads a file to the sandbox. The file is placed in /home/daytona/.

  • file: IO — File-like object to upload.
  • description: str — Description of the file, explaining its purpose and the type of data it contains.
  • Returns: SandboxUploadedFile — Metadata about the uploaded file.

Example: Suppose you want to analyze sales data for a retail business. You have a CSV file named sales_q3_2025.csv containing columns like transaction_id, date, product, quantity, and revenue. You want to upload this file and provide a description that gives context for the analysis.

with open("sales_q3_2025.csv", "rb") as f:
    uploaded = tool.upload_file(
        f,
        "CSV file containing Q3 2025 retail sales transactions. Columns: transaction_id, date, product, quantity, revenue."
    )

remove_uploaded_file(uploaded_file)

Removes a previously uploaded file from the sandbox.

Example:

# Remove an uploaded file
tool.remove_uploaded_file(uploaded)

get_sandbox()

Gets the current sandbox instance.

  • Returns: Sandbox — Sandbox instance.

This method provides access to the Daytona sandbox instance, allowing you to inspect sandbox properties and metadata, as well as perform any sandbox-related operations. For details on available attributes and methods, see the Sandbox data structure section below.

Example:

sandbox = tool.get_sandbox()

install_python_packages(package_names)

Installs one or more Python packages in the sandbox using pip.

  • package_names: str or List[str] — Name(s) of the package(s) to install.

Note: The list of preinstalled packages in a sandbox can be found at Daytona Default Snapshot documentation.

Example:

# Install a single package
tool.install_python_packages("pandas")

# Install multiple packages
tool.install_python_packages(["numpy", "matplotlib"])

close()

Closes and deletes the sandbox environment.

Note: Call this method when you are finished with all data analysis tasks to properly clean up resources and avoid unnecessary usage.

Example:

# Close the sandbox and clean up
tool.close()

Data Structures

SandboxUploadedFile

Represents metadata about a file uploaded to the sandbox.

  • name: str — Name of the uploaded file in the sandbox
  • remote_path: str — Full path to the file in the sandbox
  • description: str — Description provided during upload

Sandbox

Represents a Daytona sandbox instance.

See the full structure and API in the Daytona Python SDK Sandbox documentation.

Metadata

Release files for langchain-daytona-data-analysis 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-daytona-data-analysis 0.2.3
File Size Uploaded Provenance Actions
langchain_daytona_data_analysis-0.2.3.tar.gz 8.1 kB With provenance Details for langchain_daytona_data_analysis-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-daytona-data-analysis 0.2.3
File Interpreter ABI Platform Actions
langchain_daytona_data_analysis-0.2.3-py3-none-any.whl Python 3 none any Details for langchain_daytona_data_analysis-0.2.3-py3-none-any.whl

Total release size: 17.4 kB

Release files / langchain_daytona_data_analysis-0.2.3.tar.gz

Download URL langchain_daytona_data_analysis-0.2.3.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4f170b3510a5ea4607497453579654d05a91176eb17b6f846da0352453060132
BLAKE2b-256 checksum
How to use checksums
92bf17973fa2e4a33d72eeeb61d3bcdeb46a5e3fc5a3c800aaccfa3d999c68b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / langchain_daytona_data_analysis-0.2.3-py3-none-any.whl

Download URL langchain_daytona_data_analysis-0.2.3-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0903263b8731ebcb8ba458544899c96671cf78203c00423c823e5da83c6bfcc8
BLAKE2b-256 checksum
How to use checksums
b7779785811ac0bbc797024da497bae9e5f35c819fd6fb1ed99743b1b85464e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for langchain-daytona-data-analysis 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_daytona_data_analysis-0.2.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page