Skip to main content
This guide provides a quick overview for getting started with the DaytonaDataAnalysisTool.
Detailed Usage ExampleFor a detailed usage example of this tool, see the Daytona documentation.

Overview

Details

ClassPackageSerializableJS support
DaytonaDataAnalysisToollangchain-daytona-data-analysis❌❌

Features

  • πŸ”’ Secure sandboxed execution - Run Python code in isolated environments
  • 🐍 Python data analysis - Perform data analysis tasks with full Python capabilities
  • πŸ“ File management - Upload and download files to/from the sandbox
  • πŸ”„ Multi-step workflows - Support for complex, multi-step data analysis processes
  • 🎯 Custom result handling - Use callbacks to process execution results
  • πŸ“¦ Package management - Install Python packages dynamically in the sandbox

Setup

To access the DaytonaDataAnalysisTool, you’ll need to create a Daytona account, get an API key, and install the langchain-daytona-data-analysis integration package.

Credentials

You must configure credentials for Daytona. You can do this in one of three ways: 1. Set the DAYTONA_API_KEY environment variable:
Set API key
export DAYTONA_API_KEY="your-daytona-api-key"
2. Add it to a .env file in your project root:
Set API key
DAYTONA_API_KEY=your-daytona-api-key
3. Pass the API key directly when instantiating DaytonaDataAnalysisTool:
Set API key
tool = DaytonaDataAnalysisTool(daytona_api_key="your-daytona-api-key")
It’s also helpful (but not needed) to set up LangSmith for best-in-class observability/ of your tool calls. To enable automated tracing, set your LangSmith API key:
Enable tracing
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"

Installation

The DaytonaDataAnalysisTool lives in the langchain-daytona-data-analysis package:

From PyPI

Install the package directly from PyPI:
pip install langchain-daytona-data-analysis

From GitHub

Install the latest development version from GitHub:
pip install git+https://github.com/daytonaio/langchain_daytona_data_analysis

Instantiation

Import and instantiate the tool:
Initialize tool instance
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 pass if not set as DAYTONA_API_KEY environment variable
    on_result=process_data_analysis_result
)

Invocation

Directly

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

As a ToolCall

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

tool.invoke(model_generated_tool_call)

Within an agent

Agent with tool
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])

Additional functionalities

The DaytonaDataAnalysisTool provides several methods for managing files and the sandbox environment:

File Management

Upload files to the sandbox:
with open("sales_data.csv", "rb") as f:
    uploaded = tool.upload_file(
        f,
        "CSV file containing sales data with columns: id, date, product, revenue"
    )
Download files from the sandbox:
file_bytes = tool.download_file("/home/daytona/results.csv")
Remove uploaded files:
tool.remove_uploaded_file(uploaded)

Package Management

Install Python packages in the sandbox:
# Single package
tool.install_python_packages("pandas")

# Multiple packages
tool.install_python_packages(["numpy", "matplotlib", "seaborn"])
For a list of preinstalled packages, see the Daytona Default Snapshot documentation.

Sandbox Management

Access the sandbox instance:
sandbox = tool.get_sandbox()
Close the sandbox when finished:
tool.close()  # Cleans up resources and deletes the sandbox
Call tool.close() when you’re finished with all data analysis tasks to properly clean up resources and avoid unnecessary usage.

API reference

For detailed documentation of all DaytonaDataAnalysisTool features and configurations, head to the API reference.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.