Skip to main content
Build systems and CI/CD pipelines often require clean, isolated environments to ensure reproducibility and prevent dependency conflicts. Tensorlake Sandboxes allow you to spin up ephemeral containers on demand, upload source code, run tests, and retrieve artifacts. This example demonstrates a complete mini-CI pipeline that creates a dummy project, runs tests, and builds a distribution package inside a sandbox.

TypeScript SDK starter

If your build runner is already in Node.js, the workflow is the same: stream project files into a sandbox, run each CI step, and pull artifacts back out if needed.

Example: CI/CD Pipeline

The following script simulates a CI pipeline. It generates a simple Python project, uploads it to a sandbox, installs dependencies, runs pytest, and builds a wheel file.

How It Works

  1. Environment Creation: The script instantiates a fresh sandbox. This ensures no leftover files or environment variables from previous builds affect the current run.
  2. File Injection: The custom copy_to_sandbox function walks the local directory tree and streams files into the sandbox using sandbox.write_file(). This simulates the β€œcheckout” phase of a CI pipeline.
  3. Step Execution: The run_ci_step helper function executes shell commands (like pip and pytest) inside the sandbox using sandbox.run(). It captures stdout, stderr, and exit codes to determine success or failure.
  4. Artifact Generation: The build step generates .whl and .tar.gz files inside the sandbox. In a real-world scenario, you would use sandbox.read_file() to download these artifacts back to your storage.

Learn More

File Operations

Learn how to efficiently move large files and directories in and out of sandboxes.

Commands & Processes

Run commands, manage long-running processes, and handle exit codes.