返回 Skill 列表
extension
分类: 开发与工程无需 API Key

modal-sandbox

使用ComputeSDK创建和管理Modal沙箱的指南。在构建需要Modal的GPU加速沙箱环境的应用程序时使用,适用于机器学习工作负载、AI推理或计算密集型代码执行。

person作者: jakexiaohubgithub

Modal Sandboxes with ComputeSDK

Modal provider for ComputeSDK - serverless Python execution with GPU support and zero cold starts.

Setup

npm install computesdk @computesdk/modal

Set your credentials:

# .env
MODAL_TOKEN_ID=your_modal_token_id
MODAL_TOKEN_SECRET=your_modal_token_secret

Quick Start

import { compute } from 'computesdk';
import { modal } from '@computesdk/modal';

compute.setConfig({
  provider: modal({
    tokenId: process.env.MODAL_TOKEN_ID,
    tokenSecret: process.env.MODAL_TOKEN_SECRET,
  }),
});

const sandbox = await compute.sandbox.create();

const result = await sandbox.runCommand('echo "Hello from Modal!"');
console.log(result.stdout);

await sandbox.destroy();

You can also call the provider factory directly:

import { modal } from '@computesdk/modal';

const sdk = modal({
    tokenId: process.env.MODAL_TOKEN_ID,
    tokenSecret: process.env.MODAL_TOKEN_SECRET,
  });
const sandbox = await sdk.sandbox.create();

Modal Configuration

interface ModalConfig {

  tokenId?: string;
  tokenSecret?: string;
  timeout?: number;
  environment?: string;
  ports?: number[];
  daemonSsePort?: number | false;
  appName?: string;
  scalableSandboxes?: boolean;

}

Full API

ComputeSDK exposes the same universal sandbox API across providers: sandbox.create(), sandbox.getById(), sandbox.destroy(), sandbox.runCommand(), sandbox.getInfo(), sandbox.getUrl(), and sandbox.filesystem.*.

Install the main skill for the complete reference:

npx skills add https://github.com/computesdk/sandbox-skills --skill computesdk

Or see https://www.computesdk.com/docs/reference/sandbox/.