Install
openclaw skills install yuyonghao-code-sandboxSecure sandbox for executing Node.js, Python, Go, and Rust code with timeout, CPU, and isolated temporary directory constraints.
openclaw skills install yuyonghao-code-sandbox🔒 Secure code execution sandbox for OpenClaw agents.
# Already in workspace skills directory
cd skills/code-sandbox
npm install
const { CodeSandbox } = require('./src/sandbox');
const sandbox = new CodeSandbox({
defaultTimeout: 30000, // 30 seconds
defaultMemoryLimit: 512, // 512 MB
});
// Execute Node.js code
const result = await sandbox.execute({
language: 'node',
code: 'console.log("Hello World!");',
});
console.log(result);
// {
// success: true,
// output: "Hello World!\n",
// error: "",
// exitCode: 0,
// executionTime: 45,
// memoryUsed: 0
// }
// Execute Python code
const pythonResult = await sandbox.execute({
language: 'python',
code: 'print("Hello from Python!")',
config: {
timeout: 5000, // 5 seconds
}
});
# Run demo
npm run demo
# Run tests
npm test
| Language | Version | Description |
|---|---|---|
| node | 20.x | Node.js JavaScript runtime |
| python | 3.11 | Python interpreter |
| go | 1.21 | Go compiler and runtime |
| rust | 1.75 | Rust compiler (rustc) |
const config = {
defaultTimeout: 30000, // Default timeout in ms
defaultMemoryLimit: 512, // Default memory limit in MB
defaultCpuLimit: 1, // Default CPU cores
tmpDir: '/path/to/tmp', // Temporary directory for execution
};
const sandbox = new CodeSandbox(config);
await sandbox.execute({
language: 'node',
code: '...',
config: {
timeout: 10000, // Override timeout
memoryLimit: 256, // Override memory limit
}
});
// Get last 100 executions
const history = sandbox.getHistory(100);
console.log(history);
// [
// {
// executionId: "exec_1710691200000_a1b2c3d4",
// timestamp: "2026-03-17T09:00:00.000Z",
// language: "node",
// codeLength: 42,
// success: true,
// executionTime: 45,
// memoryUsed: 0
// },
// ...
// ]
try {
const result = await sandbox.execute({
language: 'node',
code: 'throw new Error("Oops!");',
});
if (!result.success) {
console.error('Execution failed:', result.error);
}
} catch (error) {
console.error('Sandbox error:', error.message);
}
# Run all tests
npm test
# Test specific language
node test/node-test.js
node test/python-test.js
⚠️ This sandbox provides basic isolation but is NOT suitable for:
For production use, implement:
MIT License - See LICENSE file for details
Contributions welcome! Please read CONTRIBUTING.md first.
Version: 0.1.0
Last Updated: 2026-03-17
Author: OpenClaw Team