Skip to content

Sandbox

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

3 modules

ModuleDescription
รัน JavaScriptรันโค้ด JavaScript ผ่าน Node.js พร้อมกำหนดเวลาหมด
รัน Pythonรันโค้ด Python ใน subprocess พร้อมกำหนดเวลาหมด
รัน Shellรันคำสั่ง shell พร้อมกำหนดเวลาหมดและควบคุมสภาพแวดล้อม

Modules

รัน JavaScript

sandbox.execute_js

รันโค้ด JavaScript ผ่าน Node.js พร้อมกำหนดเวลาหมด

Parameters:

NameTypeRequiredDefaultDescription
codestringYes-โค้ด JavaScript ที่จะรันผ่าน Node.js
timeoutnumberNo10เวลาหมดในการรันเป็นวินาที

Output:

FieldTypeDescription
stdoutstringผลลัพธ์มาตรฐานจากสคริปต์
stderrstringข้อผิดพลาดมาตรฐานจากสคริปต์
exit_codenumberรหัสออกจากกระบวนการ (0 = สำเร็จ)
execution_time_msnumberเวลารันเป็นมิลลิวินาที

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));

รัน Python

sandbox.execute_python

รันโค้ด Python ใน subprocess พร้อมกำหนดเวลาหมด

Parameters:

NameTypeRequiredDefaultDescription
codestringYes-โค้ด Python ที่จะรัน
timeoutnumberNo10เวลาหมดในการรันเป็นวินาที
allowed_modulesarrayNo-รายการโมดูลที่สามารถนำเข้าได้ (ปล่อยว่างเพื่ออนุญาตทั้งหมด)

Output:

FieldTypeDescription
stdoutstringผลลัพธ์มาตรฐานจากสคริปต์
stderrstringข้อผิดพลาดมาตรฐานจากสคริปต์
exit_codenumberรหัสออกจากกระบวนการ (0 = สำเร็จ)
execution_time_msnumberเวลารันเป็นมิลลิวินาที

Example: Simple print

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

Example: Math calculation

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

รัน Shell

sandbox.execute_shell

รันคำสั่ง shell พร้อมกำหนดเวลาหมดและควบคุมสภาพแวดล้อม

Parameters:

NameTypeRequiredDefaultDescription
commandstringYes-คำสั่ง shell ที่จะรัน
timeoutnumberNo10เวลาหมดในการรันเป็นวินาที
working_dirstringNo-ไดเรกทอรีทำงานสำหรับคำสั่ง
envobjectNo-ตัวแปรสภาพแวดล้อมเพิ่มเติมที่จะตั้งค่า (รวมกับสภาพแวดล้อมปัจจุบัน)

Output:

FieldTypeDescription
stdoutstringผลลัพธ์มาตรฐานจากคำสั่ง
stderrstringข้อผิดพลาดมาตรฐานจากคำสั่ง
exit_codenumberรหัสออกจากกระบวนการ (0 = สำเร็จ)
execution_time_msnumberเวลารันเป็นมิลลิวินาที

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.