@ computesdk/ tenki (帮助)
腾基云 computeSDK的提供商 - 在有本地文件系统操作的快微VM沙盒中运行代码,公共预览URL,快照,卷,和SSH.
安装
npm install @computesdk/tenki
需要Node.js 20或后期(Tenki SDK的gRPC运输依赖于它).
设置
- 报名到 app.tenki.cloud (英语)
- 在工作空间设置中创建 API 密钥
- 设定为环境变量:
export TENKI_API_KEY=tk_your_api_key
使用量
使用计算SDK
import { compute } from 'computesdk';
import { tenki } from '@computesdk/tenki';
compute.setConfig({ provider: tenki({ apiKey: process.env.TENKI_API_KEY }) });
const sandbox = await compute.instances.create();
const result = await sandbox.runCommand('echo "Hello from Tenki!"');
console.log(result.stdout);
await sandbox.destroy();
文件系统操作
Tenki 在其数据平面上暴露出本土文件原始, 因此文件系统操作不会通过 shell 命令( 没有逃脱危险, 使用任何路径或内容的工作) :
await sandbox.filesystem.writeFile('/home/tenki/app.py', 'print("hi")');
const content = await sandbox.filesystem.readFile('/home/tenki/app.py');
const entries = await sandbox.filesystem.readdir('/home/tenki');
await sandbox.filesystem.mkdir('/home/tenki/data');
const exists = await sandbox.filesystem.exists('/home/tenki/app.py');
await sandbox.filesystem.remove('/home/tenki/app.py');
公开预览 URL
// Start a server (background commands are detached automatically)
await sandbox.runCommand('python3 -m http.server 3000', { background: true });
// Expose the port at a public URL
const url = await sandbox.getUrl({ port: 3000 });
// => https://<slug>.sb.tenki.sh
配置
| 选项 | 新闻 var | 默认 | 说明 |
|---|---|---|---|
apiKey | TENKI_API_KEY 编号 : TENKI_AUTH_TOKEN | 所需经费 | Tenki API 密钥 (tk_...(中文(简体) ) |
baseUrl | TENKI_API_URL | https://api.tenki.cloud | API 终点 |
workspaceId | TENKI_WORKSPACE_ID | 从工作空间 API 密钥推断 | 信任服务证书的明确工作空间 |
projectId | - 说吧 | 忽略 | 折旧;Tenki不再按项目标出沙箱 |
timeout | - 说吧 | 无 | 默认 runCommand 超时( 毫秒) |
cpuCores 编号 : memoryMb 编号 : diskSizeGb | - 说吧 | Tenki 默认 | 默认沙盒资源 |
工作空间 API 键推断他们的工作空间服务器侧. 设定 workspaceId,或 TENKI_WORKSPACE_ID,只有当使用需要明确范围的可信服务证书时.
单相框资源覆盖被接受于 create数字 :
await compute.instances.create({ cpuCores: 4, memoryMb: 8192 });
特性支持
| 特性 | 支助 |
|---|---|
图标( E)runCommand(中文(简体) ) | 是的 - 通过 sh -lc所以管子,花纹, 和管道扩展工作 |
| 文件系统 | 是 - 本地数据平面文件 API |
公共 URL (英语:getUrl(中文(简体) ) | 是 - 每端预览 URL |
| 列表 / 获取ById / 销毁 | 对 |
| 背景命令 | 对.. { background: true } 自动解析 stdio |
| 自定义图像 | Via Tenki 模板(templateId 地图到 Tenki 图像参考) |
| 暂停/ 恢复 | 对.. sandbox.pause() 编号 : sandbox.resume(); 内存、进程和文件(包括 /tmp(活下来) |
| 抓图 | 对.. compute.snapshot.create(id),用 create({ snapshotId }); 保存 rootf 的内存快照 /tmp (源头也空了)源头不停地运行 |
页:1
runCommand将命令包入sh -lc因为 Tenki 的执行直接运行 argv(执行,无外壳).- 一个长期的过程从一个裸体开始
&使执行输出流打开; 使用{ background: true }为你解开口. - 对于高级特性(SSH,地道,git操作),直接通过基础SDK
sandbox.getInstance(),返回@tenkicloud/sandboxSession。 。 。 .
许可证
麻省理工学院