执行任务 | 大装置帮助中心
跳到主要内容

执行任务

POST https://sandbox.cn-sh-01.sensecoreapi.cn/studio/sandbox/v1/workspaces/{workspace_id}/sandboxGroups/{sandbox_group_id}:execute

请求头(Request Header)

请参考API 使用指南

请求参数(Request Parameters)

名称类型必须位置描述
workspace_idstringpath工作空间id,获取方式可以参考快速开始
sandbox_group_idstringpath沙盒组id
execute_contentobjectbody执行内容

其中execute_content的参数如下:

名称类型必须位置描述
sandbox_idstringbody沙盒实例id,若不传入,系统将从沙盒组中任选一个沙盒实例进行任务执行
codestringbody待执行代码
languagestringbody编程语言,当前仅支持python
execution_timeoutintegerbody代码执行超时时间,单位为秒,可设置范围为(0,300],默认值为60秒。该参数仅设置接口中代码执行部分的超时,整体接口超时时间为10分钟,包含数据上传下载以及代码执行。
stdinstringbody标准输入
upload_filesobjectbody上传文件内容,key:value形式,其中key中需要填写文件在沙盒中的存放路径,value为文件base64内容
fetch_filesarraybody任务执行后需要获取的文件路径

请求示例(Request Example)

curl -L -X POST 'https://sandbox.cn-sh-01.sensecoreapi.cn/studio/sandbox/v1/workspaces/01993ca4-edfa-7382-8161-43a4919681ab/sandboxGroups/c8e381e5-491c-47cf-842b-aacf914a8c35:execute' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"execute_content":{
"code":"print('\''Hello World!'\'')",
"language":"python"
}
}'

响应(Response)

异常情况请参考异常响应说明

字段类型描述
sandbox_idstring执行任务所用的sandbox_id
resultobject执行结果
filesobject下载的文件内容,key:value形式,key中为文件路径,value中为文件内容base64编码,若为空,则不返回该字段

其中,result的参数如下:

字段类型描述
exit_codeint32退出码
stdoutstring标准输出
stderrstring标准错误
execution_timeint64执行耗时(毫秒)

响应示例(Response Example)

  • 正常响应
{
"result": {
"stdout": "Hello World!\n",
"sandbox_id": "1456826b-5f89-41fd-90b0-77b2b464d5ba"
},
"sandbox_id": "1456826b-5f89-41fd-90b0-77b2b464d5ba"
}