Skip to main content

What You’ll Learn

  • How to upload a dataset file with sbx.files.write()
  • How to write and execute a Python analysis script inside the sandbox
  • How to read structured JSON results back using sbx.files.read()
  • The upload-compute-download pattern for safe, isolated data processing

Prerequisites

  • Declaw running locally or in the cloud (see Deployment)
  • DECLAW_API_KEY and DECLAW_DOMAIN set in your environment

Code Walkthrough

1. Define the dataset and analysis script

Both the CSV data and the analysis script are defined as Python strings and uploaded to the sandbox filesystem:

2. Upload, execute, and read back

Expected Output

Pattern Notes

Why run the analysis inside the sandbox instead of locally?
  • The analysis script could be untrusted (for example, user-submitted code in a data pipeline)
  • The dataset may contain sensitive data that should not be processed on the host
  • Sandbox isolation ensures the script cannot access host files, environment variables, or network resources
Scaling the pattern:
  • Use sbx.files.write_files() to upload multiple files in a single API call
  • Use sbx.commands.run_stream() for long-running analyses where you want incremental output
  • Add allow_internet_access=False to block all outbound network access during analysis