Skip to content

Sandbox

Execute JavaScript, Python, or shell commands in isolated environments.

3 modules

ModuleDescription
Chạy JavaScriptChạy mã JavaScript qua Node.js với thời gian chờ
Chạy PythonChạy mã Python trong một tiến trình phụ với thời gian chờ
Chạy ShellChạy lệnh shell với thời gian chờ và kiểm soát môi trường

Modules

Chạy JavaScript

sandbox.execute_js

Chạy mã JavaScript qua Node.js với thời gian chờ

Parameters:

NameTypeRequiredDefaultDescription
codestringYes-Mã JavaScript để chạy qua Node.js
timeoutnumberNo10Thời gian chờ chạy tính bằng giây

Output:

FieldTypeDescription
stdoutstringĐầu ra chuẩn từ script
stderrstringLỗi chuẩn từ script
exit_codenumberMã thoát của tiến trình (0 = thành công)
execution_time_msnumberThời gian chạy tính bằng mili giây

Example: Simple console.log

yaml
code: console.log("Hello, World!");
timeout: 10

Example: JSON processing

yaml
code: const data = { name: "test", value: 42 };
console.log(JSON.stringify(data, null, 2));

Chạy Python

sandbox.execute_python

Chạy mã Python trong một tiến trình phụ với thời gian chờ

Parameters:

NameTypeRequiredDefaultDescription
codestringYes-Mã Python để chạy
timeoutnumberNo10Thời gian chờ chạy tính bằng giây
allowed_modulesarrayNo-Danh sách trắng các mô-đun có thể nhập (để trống để cho phép tất cả)

Output:

FieldTypeDescription
stdoutstringĐầu ra chuẩn từ script
stderrstringLỗi chuẩn từ script
exit_codenumberMã thoát của tiến trình (0 = thành công)
execution_time_msnumberThời gian chạy tính bằng mili giây

Example: Simple print

yaml
code: print("Hello, World!")
timeout: 10

Example: Math calculation

yaml
code: import math
print(math.pi)
allowed_modules: ["math"]

Chạy Shell

sandbox.execute_shell

Chạy lệnh shell với thời gian chờ và kiểm soát môi trường

Parameters:

NameTypeRequiredDefaultDescription
commandstringYes-Lệnh shell để chạy
timeoutnumberNo10Thời gian chờ chạy tính bằng giây
working_dirstringNo-Thư mục làm việc cho lệnh
envobjectNo-Các biến môi trường bổ sung để thiết lập (kết hợp với môi trường hiện tại)

Output:

FieldTypeDescription
stdoutstringĐầu ra chuẩn từ lệnh
stderrstringLỗi chuẩn từ lệnh
exit_codenumberMã thoát của tiến trình (0 = thành công)
execution_time_msnumberThời gian chạy tính bằng mili giây

Example: Simple echo

yaml
command: echo "Hello, World!"
timeout: 10

Example: List files with custom working directory

yaml
command: ls -la
working_dir: /tmp

Released under the Apache 2.0 License.