Modal
Modal provider for ComputeSDK - Execute code with GPU support for machine learning workloads.
Installation
Section titled “Installation”npm install @computesdk/modalWith ComputeSDK
Section titled “With ComputeSDK”import { createCompute } from 'computesdk';
import { modal } from '@computesdk/modal';
// Set as default provider
const compute = createCompute({
provider: modal({
tokenId: process.env.MODAL_TOKEN_ID,
tokenSecret: process.env.MODAL_TOKEN_SECRET
}),
apiKey: process.env.COMPUTESDK_API_KEY
});
// Create sandbox
const sandbox = await compute.sandbox.create();
// Get instance
const instance = sandbox.getInstance();
// Execute code
const result = await sandbox.runCode('print("Hello from Modal!")');
console.log(result.stdout); // "Hello from Modal!"
// Clean up
await compute.sandbox.destroy(sandbox.sandboxId);Configuration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”export MODAL_TOKEN_ID=your_modal_token_id_here
export MODAL_TOKEN_SECRET=your_modal_token_secret_hereConfiguration Options
Section titled “Configuration Options”interface ModalConfig {
/** Modal token ID - if not provided, will use MODAL_TOKEN_ID env var */
tokenId?: string;
/** Modal token secret - if not provided, will use MODAL_TOKEN_SECRET env var */
tokenSecret?: string;
/** Runtime to use */
runtime?: 'node' | 'python';
/** Execution timeout in milliseconds */
timeout?: number;
/** Modal environment (sandbox or main) */
environment?: string;
}SDK Reference Links:
Section titled “SDK Reference Links:”- Code Execution - Execute code snippets in various runtimes
- Command Execution - Run shell commands and scripts
- Filesystem Operations - Read, write, and manage files in sandboxes
- Sandbox Management - Create, list, and destroy sandboxes
- Error Handling - Handle command failures and runtime errors
- Web Framework Integration - Integrate with Express, Next.js, and other frameworks