@nahisaho/katashiro-sandbox 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +213 -0
- package/dist/docker-executor.d.ts +117 -0
- package/dist/docker-executor.d.ts.map +1 -0
- package/dist/docker-executor.js +557 -0
- package/dist/docker-executor.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/local-executor.d.ts +64 -0
- package/dist/local-executor.d.ts.map +1 -0
- package/dist/local-executor.js +242 -0
- package/dist/local-executor.js.map +1 -0
- package/dist/sandbox.d.ts +104 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +128 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/types.d.ts +228 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* KATASHIRO Sandbox - Docker Executor Implementation
|
|
4
|
+
*
|
|
5
|
+
* @fileoverview REQ-007: Dockerベースのコード実行サンドボックス
|
|
6
|
+
* @module @nahisaho/katashiro-sandbox
|
|
7
|
+
* @since 0.4.0
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.DockerExecutor = exports.SandboxError = void 0;
|
|
14
|
+
const events_1 = require("events");
|
|
15
|
+
const dockerode_1 = __importDefault(require("dockerode"));
|
|
16
|
+
const katashiro_core_1 = require("@nahisaho/katashiro-core");
|
|
17
|
+
const types_1 = require("./types");
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// エラークラス
|
|
20
|
+
// =============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* サンドボックスエラー
|
|
23
|
+
*/
|
|
24
|
+
class SandboxError extends Error {
|
|
25
|
+
code;
|
|
26
|
+
details;
|
|
27
|
+
constructor(message, code, details) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.details = details;
|
|
31
|
+
this.name = 'SandboxError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.SandboxError = SandboxError;
|
|
35
|
+
// =============================================================================
|
|
36
|
+
// Docker Executor
|
|
37
|
+
// =============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Docker Executor
|
|
40
|
+
*
|
|
41
|
+
* EARS Requirements:
|
|
42
|
+
* - Ubiquitous: The Sandbox shall execute code in an isolated Docker/VM environment
|
|
43
|
+
* - Ubiquitous: The Sandbox shall support bash, Python, and JavaScript/TypeScript execution
|
|
44
|
+
* - Event-Driven: When execution time exceeds timeout, the Sandbox shall terminate
|
|
45
|
+
* - State-Driven: While code is executing, the Sandbox shall enforce CPU and memory limits
|
|
46
|
+
* - Unwanted: If code attempts to access host system, the Sandbox shall block the access
|
|
47
|
+
*/
|
|
48
|
+
class DockerExecutor extends events_1.EventEmitter {
|
|
49
|
+
docker;
|
|
50
|
+
config;
|
|
51
|
+
dockerConfig;
|
|
52
|
+
securityPolicy;
|
|
53
|
+
activeContainers = new Map();
|
|
54
|
+
constructor(config = {}, dockerConfig = {}, securityPolicy = {}) {
|
|
55
|
+
super();
|
|
56
|
+
this.config = { ...types_1.DEFAULT_SANDBOX_CONFIG, ...config };
|
|
57
|
+
this.dockerConfig = { ...types_1.DEFAULT_DOCKER_CONFIG, ...dockerConfig };
|
|
58
|
+
this.securityPolicy = { ...types_1.DEFAULT_SECURITY_POLICY, ...securityPolicy };
|
|
59
|
+
// Docker クライアント初期化
|
|
60
|
+
this.docker = new dockerode_1.default({
|
|
61
|
+
socketPath: this.dockerConfig.socketPath,
|
|
62
|
+
host: this.dockerConfig.host,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 型安全なイベントリスナー登録
|
|
67
|
+
*/
|
|
68
|
+
on(event, listener) {
|
|
69
|
+
return super.on(event, listener);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* イベント発火
|
|
73
|
+
*/
|
|
74
|
+
emitEvent(type, data) {
|
|
75
|
+
const event = {
|
|
76
|
+
type,
|
|
77
|
+
timestamp: new Date().toISOString(),
|
|
78
|
+
...data,
|
|
79
|
+
};
|
|
80
|
+
this.emit(type, event);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* コードを実行
|
|
84
|
+
*
|
|
85
|
+
* @param code 実行するコード
|
|
86
|
+
* @param language プログラミング言語
|
|
87
|
+
* @param options 追加オプション
|
|
88
|
+
*/
|
|
89
|
+
async execute(code, language, options = {}) {
|
|
90
|
+
const requestId = (0, katashiro_core_1.generateId)();
|
|
91
|
+
const timeout = options.timeout ?? this.config.timeout;
|
|
92
|
+
const startTime = Date.now();
|
|
93
|
+
// リクエスト作成
|
|
94
|
+
const request = {
|
|
95
|
+
id: requestId,
|
|
96
|
+
code,
|
|
97
|
+
language,
|
|
98
|
+
stdin: options.stdin,
|
|
99
|
+
env: options.env,
|
|
100
|
+
timeout,
|
|
101
|
+
createdAt: new Date().toISOString(),
|
|
102
|
+
};
|
|
103
|
+
this.emitEvent('execution:start', { requestId });
|
|
104
|
+
let container;
|
|
105
|
+
try {
|
|
106
|
+
// コンテナ作成
|
|
107
|
+
container = await this.createContainer(request);
|
|
108
|
+
this.activeContainers.set(requestId, container);
|
|
109
|
+
this.emitEvent('container:create', {
|
|
110
|
+
requestId,
|
|
111
|
+
containerId: container.id,
|
|
112
|
+
});
|
|
113
|
+
// コンテナ起動
|
|
114
|
+
await container.start();
|
|
115
|
+
this.emitEvent('container:start', {
|
|
116
|
+
requestId,
|
|
117
|
+
containerId: container.id,
|
|
118
|
+
});
|
|
119
|
+
// タイムアウト設定
|
|
120
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
reject(new SandboxError('Execution timeout', 'TIMEOUT', { timeout }));
|
|
123
|
+
}, timeout * 1000);
|
|
124
|
+
});
|
|
125
|
+
// 実行結果待機(タイムアウト付き)
|
|
126
|
+
const resultPromise = this.waitForCompletion(container, request);
|
|
127
|
+
const result = await Promise.race([resultPromise, timeoutPromise]);
|
|
128
|
+
const duration = Date.now() - startTime;
|
|
129
|
+
// 出力ファイル取得
|
|
130
|
+
const files = await this.extractOutputFiles(container);
|
|
131
|
+
const executionResult = {
|
|
132
|
+
requestId,
|
|
133
|
+
status: result.exitCode === 0 ? 'completed' : 'failed',
|
|
134
|
+
exitCode: result.exitCode,
|
|
135
|
+
stdout: result.stdout,
|
|
136
|
+
stderr: result.stderr,
|
|
137
|
+
duration,
|
|
138
|
+
files,
|
|
139
|
+
completedAt: new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
this.emitEvent('execution:complete', { requestId, data: executionResult });
|
|
142
|
+
return (0, katashiro_core_1.ok)(executionResult);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const duration = Date.now() - startTime;
|
|
146
|
+
const execError = this.parseError(error);
|
|
147
|
+
const executionResult = {
|
|
148
|
+
requestId,
|
|
149
|
+
status: execError.code === 'TIMEOUT' ? 'timeout' : 'failed',
|
|
150
|
+
exitCode: -1,
|
|
151
|
+
stdout: '',
|
|
152
|
+
stderr: execError.message,
|
|
153
|
+
duration,
|
|
154
|
+
files: [],
|
|
155
|
+
error: execError,
|
|
156
|
+
completedAt: new Date().toISOString(),
|
|
157
|
+
};
|
|
158
|
+
if (execError.code === 'TIMEOUT') {
|
|
159
|
+
this.emitEvent('execution:timeout', { requestId, data: executionResult });
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.emitEvent('execution:error', { requestId, data: executionResult });
|
|
163
|
+
}
|
|
164
|
+
return (0, katashiro_core_1.err)(new SandboxError(execError.message, execError.code, { requestId }));
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
// クリーンアップ
|
|
168
|
+
if (container) {
|
|
169
|
+
await this.cleanupContainer(container, requestId);
|
|
170
|
+
}
|
|
171
|
+
this.activeContainers.delete(requestId);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* コンテナを作成
|
|
176
|
+
*/
|
|
177
|
+
async createContainer(request) {
|
|
178
|
+
const image = this.dockerConfig.images[request.language];
|
|
179
|
+
const containerName = `${this.dockerConfig.containerPrefix}${request.id}`;
|
|
180
|
+
// コード実行用のコマンドを生成
|
|
181
|
+
const { cmd, entrypoint } = this.buildCommand(request);
|
|
182
|
+
// セキュリティオプション
|
|
183
|
+
const securityOpts = ['no-new-privileges'];
|
|
184
|
+
// Ulimit設定
|
|
185
|
+
const ulimits = [
|
|
186
|
+
{ Name: 'nproc', Soft: this.securityPolicy.maxProcesses, Hard: this.securityPolicy.maxProcesses },
|
|
187
|
+
{ Name: 'nofile', Soft: this.securityPolicy.maxOpenFiles, Hard: this.securityPolicy.maxOpenFiles },
|
|
188
|
+
];
|
|
189
|
+
// コンテナ作成
|
|
190
|
+
const container = await this.docker.createContainer({
|
|
191
|
+
Image: image,
|
|
192
|
+
name: containerName,
|
|
193
|
+
Cmd: cmd,
|
|
194
|
+
Entrypoint: entrypoint,
|
|
195
|
+
Env: this.buildEnv(request.env),
|
|
196
|
+
WorkingDir: this.config.workingDir,
|
|
197
|
+
NetworkDisabled: !this.config.networkEnabled,
|
|
198
|
+
AttachStdout: true,
|
|
199
|
+
AttachStderr: true,
|
|
200
|
+
AttachStdin: !!request.stdin,
|
|
201
|
+
OpenStdin: !!request.stdin,
|
|
202
|
+
Tty: false,
|
|
203
|
+
HostConfig: {
|
|
204
|
+
AutoRemove: false, // 結果取得後に手動削除
|
|
205
|
+
Memory: this.config.memoryLimit,
|
|
206
|
+
MemorySwap: this.config.memoryLimit, // スワップ無効化
|
|
207
|
+
CpuPeriod: 100000,
|
|
208
|
+
CpuQuota: Math.floor(this.config.cpuLimit * 100000),
|
|
209
|
+
ReadonlyRootfs: false, // /workspaceへの書き込みを許可するため
|
|
210
|
+
SecurityOpt: securityOpts,
|
|
211
|
+
Ulimits: ulimits,
|
|
212
|
+
Tmpfs: {
|
|
213
|
+
'/tmp': `size=${this.config.tmpfsSize}`,
|
|
214
|
+
},
|
|
215
|
+
// CapDropでケーパビリティを削除
|
|
216
|
+
CapDrop: ['ALL'],
|
|
217
|
+
CapAdd: ['CHOWN', 'SETUID', 'SETGID'],
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
// コードをコンテナにコピー
|
|
221
|
+
await this.copyCodeToContainer(container, request);
|
|
222
|
+
return container;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 実行コマンドを構築
|
|
226
|
+
*/
|
|
227
|
+
buildCommand(request) {
|
|
228
|
+
const codeFile = this.getCodeFileName(request.language);
|
|
229
|
+
switch (request.language) {
|
|
230
|
+
case 'bash':
|
|
231
|
+
return {
|
|
232
|
+
cmd: ['/bin/sh', `${this.config.workingDir}/${codeFile}`],
|
|
233
|
+
};
|
|
234
|
+
case 'python':
|
|
235
|
+
return {
|
|
236
|
+
cmd: ['python3', `${this.config.workingDir}/${codeFile}`],
|
|
237
|
+
};
|
|
238
|
+
case 'javascript':
|
|
239
|
+
return {
|
|
240
|
+
cmd: ['node', `${this.config.workingDir}/${codeFile}`],
|
|
241
|
+
};
|
|
242
|
+
case 'typescript':
|
|
243
|
+
// TypeScriptはts-nodeまたはtsxで実行
|
|
244
|
+
return {
|
|
245
|
+
cmd: ['npx', 'tsx', `${this.config.workingDir}/${codeFile}`],
|
|
246
|
+
};
|
|
247
|
+
default:
|
|
248
|
+
throw new SandboxError(`Unsupported language: ${request.language}`, 'UNSUPPORTED_LANGUAGE');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 言語に対応するファイル名を取得
|
|
253
|
+
*/
|
|
254
|
+
getCodeFileName(language) {
|
|
255
|
+
const extensions = {
|
|
256
|
+
bash: 'script.sh',
|
|
257
|
+
python: 'script.py',
|
|
258
|
+
javascript: 'script.js',
|
|
259
|
+
typescript: 'script.ts',
|
|
260
|
+
};
|
|
261
|
+
return extensions[language];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 環境変数を構築
|
|
265
|
+
*/
|
|
266
|
+
buildEnv(env) {
|
|
267
|
+
const baseEnv = ['PATH=/usr/local/bin:/usr/bin:/bin'];
|
|
268
|
+
if (!env)
|
|
269
|
+
return baseEnv;
|
|
270
|
+
return [
|
|
271
|
+
...baseEnv,
|
|
272
|
+
...Object.entries(env).map(([key, value]) => `${key}=${value}`),
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* コードをコンテナにコピー
|
|
277
|
+
*/
|
|
278
|
+
async copyCodeToContainer(container, request) {
|
|
279
|
+
const codeFile = this.getCodeFileName(request.language);
|
|
280
|
+
// tarアーカイブを作成
|
|
281
|
+
const tar = await this.createTarArchive(codeFile, request.code);
|
|
282
|
+
// コンテナにコピー
|
|
283
|
+
await container.putArchive(tar, { path: this.config.workingDir });
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* tarアーカイブを作成(簡易版)
|
|
287
|
+
*/
|
|
288
|
+
async createTarArchive(filename, content) {
|
|
289
|
+
// tarヘッダを構築(512バイトブロック)
|
|
290
|
+
const contentBuffer = Buffer.from(content, 'utf-8');
|
|
291
|
+
const header = Buffer.alloc(512);
|
|
292
|
+
// ファイル名(最大100文字)
|
|
293
|
+
header.write(filename, 0, 100, 'utf-8');
|
|
294
|
+
// ファイルモード(8進数文字列)
|
|
295
|
+
header.write('0000755', 100, 7, 'utf-8');
|
|
296
|
+
header.write('\0', 107);
|
|
297
|
+
// UID
|
|
298
|
+
header.write('0000000', 108, 7, 'utf-8');
|
|
299
|
+
header.write('\0', 115);
|
|
300
|
+
// GID
|
|
301
|
+
header.write('0000000', 116, 7, 'utf-8');
|
|
302
|
+
header.write('\0', 123);
|
|
303
|
+
// サイズ(8進数文字列)
|
|
304
|
+
const sizeStr = contentBuffer.length.toString(8).padStart(11, '0');
|
|
305
|
+
header.write(sizeStr, 124, 11, 'utf-8');
|
|
306
|
+
header.write('\0', 135);
|
|
307
|
+
// 変更時刻
|
|
308
|
+
const mtime = Math.floor(Date.now() / 1000).toString(8).padStart(11, '0');
|
|
309
|
+
header.write(mtime, 136, 11, 'utf-8');
|
|
310
|
+
header.write('\0', 147);
|
|
311
|
+
// チェックサム用スペース
|
|
312
|
+
header.fill(' ', 148, 156);
|
|
313
|
+
// タイプフラグ(0 = 通常ファイル)
|
|
314
|
+
header.write('0', 156, 1, 'utf-8');
|
|
315
|
+
// リンク名(空)
|
|
316
|
+
// UStar indicator
|
|
317
|
+
header.write('ustar', 257, 5, 'utf-8');
|
|
318
|
+
header.write('00', 263, 2, 'utf-8');
|
|
319
|
+
// チェックサム計算
|
|
320
|
+
let checksum = 0;
|
|
321
|
+
for (let i = 0; i < 512; i++) {
|
|
322
|
+
checksum += header[i] ?? 0;
|
|
323
|
+
}
|
|
324
|
+
const checksumStr = checksum.toString(8).padStart(6, '0');
|
|
325
|
+
header.write(checksumStr, 148, 6, 'utf-8');
|
|
326
|
+
header.write('\0 ', 154, 2);
|
|
327
|
+
// コンテンツをパディング
|
|
328
|
+
const padding = 512 - (contentBuffer.length % 512);
|
|
329
|
+
const paddedContent = padding === 512
|
|
330
|
+
? contentBuffer
|
|
331
|
+
: Buffer.concat([contentBuffer, Buffer.alloc(padding)]);
|
|
332
|
+
// 終端ブロック(2つの空ブロック)
|
|
333
|
+
const endBlock = Buffer.alloc(1024);
|
|
334
|
+
return Buffer.concat([header, paddedContent, endBlock]);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* コンテナの完了を待機
|
|
338
|
+
*/
|
|
339
|
+
async waitForCompletion(container, request) {
|
|
340
|
+
// stdin送信(あれば)
|
|
341
|
+
if (request.stdin) {
|
|
342
|
+
const stream = await container.attach({
|
|
343
|
+
stream: true,
|
|
344
|
+
stdin: true,
|
|
345
|
+
hijack: true,
|
|
346
|
+
});
|
|
347
|
+
stream.write(request.stdin);
|
|
348
|
+
stream.end();
|
|
349
|
+
}
|
|
350
|
+
// 完了待機
|
|
351
|
+
const waitResult = await container.wait();
|
|
352
|
+
// ログ取得
|
|
353
|
+
const logs = await container.logs({
|
|
354
|
+
stdout: true,
|
|
355
|
+
stderr: true,
|
|
356
|
+
follow: false,
|
|
357
|
+
});
|
|
358
|
+
// ログをパース(Docker multiplexed stream format)
|
|
359
|
+
const { stdout, stderr } = this.parseLogs(logs);
|
|
360
|
+
return {
|
|
361
|
+
exitCode: waitResult.StatusCode,
|
|
362
|
+
stdout,
|
|
363
|
+
stderr,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Dockerログをパース
|
|
368
|
+
*/
|
|
369
|
+
parseLogs(logs) {
|
|
370
|
+
if (Buffer.isBuffer(logs)) {
|
|
371
|
+
// Docker multiplexed stream format
|
|
372
|
+
let stdout = '';
|
|
373
|
+
let stderr = '';
|
|
374
|
+
let offset = 0;
|
|
375
|
+
while (offset < logs.length) {
|
|
376
|
+
if (offset + 8 > logs.length)
|
|
377
|
+
break;
|
|
378
|
+
const streamType = logs[offset];
|
|
379
|
+
const size = logs.readUInt32BE(offset + 4);
|
|
380
|
+
offset += 8;
|
|
381
|
+
if (offset + size > logs.length)
|
|
382
|
+
break;
|
|
383
|
+
const chunk = logs.slice(offset, offset + size).toString('utf-8');
|
|
384
|
+
offset += size;
|
|
385
|
+
if (streamType === 1) {
|
|
386
|
+
stdout += chunk;
|
|
387
|
+
}
|
|
388
|
+
else if (streamType === 2) {
|
|
389
|
+
stderr += chunk;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return { stdout, stderr };
|
|
393
|
+
}
|
|
394
|
+
// ストリームの場合(未実装)
|
|
395
|
+
return { stdout: '', stderr: '' };
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 出力ファイルを抽出
|
|
399
|
+
*/
|
|
400
|
+
async extractOutputFiles(_container) {
|
|
401
|
+
// 現時点では出力ファイルの抽出は未実装
|
|
402
|
+
// 将来的にはworkspace内の新規・更新ファイルを検出して返す
|
|
403
|
+
return [];
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* コンテナをクリーンアップ
|
|
407
|
+
*/
|
|
408
|
+
async cleanupContainer(container, requestId) {
|
|
409
|
+
try {
|
|
410
|
+
// 実行中なら停止
|
|
411
|
+
const info = await container.inspect();
|
|
412
|
+
if (info.State.Running) {
|
|
413
|
+
await container.stop({ t: 1 });
|
|
414
|
+
}
|
|
415
|
+
// コンテナ削除
|
|
416
|
+
await container.remove({ force: true });
|
|
417
|
+
this.emitEvent('container:stop', {
|
|
418
|
+
requestId,
|
|
419
|
+
containerId: container.id,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
// クリーンアップエラーは無視
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* エラーをパース
|
|
428
|
+
*/
|
|
429
|
+
parseError(error) {
|
|
430
|
+
if (error instanceof SandboxError) {
|
|
431
|
+
return {
|
|
432
|
+
code: error.code,
|
|
433
|
+
message: error.message,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
if (error instanceof Error) {
|
|
437
|
+
return {
|
|
438
|
+
code: 'EXECUTION_ERROR',
|
|
439
|
+
message: error.message,
|
|
440
|
+
stack: error.stack,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
code: 'UNKNOWN_ERROR',
|
|
445
|
+
message: String(error),
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* アクティブなコンテナ数を取得
|
|
450
|
+
*/
|
|
451
|
+
getActiveContainerCount() {
|
|
452
|
+
return this.activeContainers.size;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* 指定した実行をキャンセル
|
|
456
|
+
*/
|
|
457
|
+
async cancel(requestId) {
|
|
458
|
+
const container = this.activeContainers.get(requestId);
|
|
459
|
+
if (!container)
|
|
460
|
+
return false;
|
|
461
|
+
try {
|
|
462
|
+
await container.stop({ t: 1 });
|
|
463
|
+
await container.remove({ force: true });
|
|
464
|
+
this.activeContainers.delete(requestId);
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* 全アクティブコンテナをクリーンアップ
|
|
473
|
+
*/
|
|
474
|
+
async cleanup() {
|
|
475
|
+
const promises = Array.from(this.activeContainers.entries()).map(async ([requestId, container]) => {
|
|
476
|
+
await this.cleanupContainer(container, requestId);
|
|
477
|
+
this.activeContainers.delete(requestId);
|
|
478
|
+
});
|
|
479
|
+
await Promise.all(promises);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* コンテナ情報を取得
|
|
483
|
+
*/
|
|
484
|
+
async getContainerInfo(requestId) {
|
|
485
|
+
const container = this.activeContainers.get(requestId);
|
|
486
|
+
if (!container)
|
|
487
|
+
return null;
|
|
488
|
+
try {
|
|
489
|
+
const info = await container.inspect();
|
|
490
|
+
return {
|
|
491
|
+
id: info.Id,
|
|
492
|
+
name: info.Name,
|
|
493
|
+
image: info.Config.Image,
|
|
494
|
+
status: info.State.Status,
|
|
495
|
+
createdAt: info.Created,
|
|
496
|
+
startedAt: info.State.StartedAt,
|
|
497
|
+
finishedAt: info.State.FinishedAt || undefined,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
catch {
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* リソース使用量を取得
|
|
506
|
+
*/
|
|
507
|
+
async getResourceStats(requestId) {
|
|
508
|
+
const container = this.activeContainers.get(requestId);
|
|
509
|
+
if (!container)
|
|
510
|
+
return null;
|
|
511
|
+
try {
|
|
512
|
+
const stats = await container.stats({ stream: false });
|
|
513
|
+
const statsData = stats;
|
|
514
|
+
// CPU使用率計算
|
|
515
|
+
const cpuDelta = statsData.cpu_stats.cpu_usage.total_usage -
|
|
516
|
+
statsData.precpu_stats.cpu_usage.total_usage;
|
|
517
|
+
const systemDelta = statsData.cpu_stats.system_cpu_usage -
|
|
518
|
+
statsData.precpu_stats.system_cpu_usage;
|
|
519
|
+
const cpuPercent = systemDelta > 0 ? (cpuDelta / systemDelta) * 100 : 0;
|
|
520
|
+
// ネットワーク統計
|
|
521
|
+
let networkTx = 0;
|
|
522
|
+
let networkRx = 0;
|
|
523
|
+
if (statsData.networks) {
|
|
524
|
+
for (const net of Object.values(statsData.networks)) {
|
|
525
|
+
networkTx += net.tx_bytes;
|
|
526
|
+
networkRx += net.rx_bytes;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// ディスクIO統計
|
|
530
|
+
let diskRead = 0;
|
|
531
|
+
let diskWrite = 0;
|
|
532
|
+
const ioStats = statsData.blkio_stats.io_service_bytes_recursive;
|
|
533
|
+
if (ioStats) {
|
|
534
|
+
for (const io of ioStats) {
|
|
535
|
+
if (io.op === 'read')
|
|
536
|
+
diskRead += io.value;
|
|
537
|
+
if (io.op === 'write')
|
|
538
|
+
diskWrite += io.value;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
memoryUsage: statsData.memory_stats.usage,
|
|
543
|
+
memoryLimit: statsData.memory_stats.limit,
|
|
544
|
+
cpuPercent,
|
|
545
|
+
networkTx,
|
|
546
|
+
networkRx,
|
|
547
|
+
diskRead,
|
|
548
|
+
diskWrite,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
catch {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
exports.DockerExecutor = DockerExecutor;
|
|
557
|
+
//# sourceMappingURL=docker-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker-executor.js","sourceRoot":"","sources":["../src/docker-executor.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,mCAAsC;AACtC,0DAA+B;AAC/B,6DAA4E;AAgB5E,mCAIiB;AAEjB,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IAGnB;IACA;IAHlB,YACE,OAAe,EACC,IAAY,EACZ,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AATD,oCASC;AAED,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;;;;;GASG;AACH,MAAa,cAAe,SAAQ,qBAAY;IAC7B,MAAM,CAAS;IACf,MAAM,CAAgB;IACtB,YAAY,CAAe;IAC3B,cAAc,CAAiB;IAC/B,gBAAgB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAExE,YACE,SAAiC,EAAE,EACnC,eAAsC,EAAE,EACxC,iBAA0C,EAAE;QAE5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,8BAAsB,EAAE,GAAG,MAAM,EAAE,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,EAAE,GAAG,6BAAqB,EAAE,GAAG,YAAY,EAAE,CAAC;QAClE,IAAI,CAAC,cAAc,GAAG,EAAE,GAAG,+BAAuB,EAAE,GAAG,cAAc,EAAE,CAAC;QAExE,mBAAmB;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAM,CAAC;YACvB,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;YACxC,IAAI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AS,IAAI,GAAG,CAAC,QAAQ,CAAC;oBAC1B,SAAS,IAAI,GAAG,CAAC,QAAQ,CAAC;gBAC5B,CAAC;YACH,CAAC;YAED,WAAW;YACX,IAAI,QAAQ,GAAG,CAAC,CAAC;YACjB,IAAI,SAAS,GAAG,CAAC,CAAC;YAClB,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,0BAA0B,CAAC;YACjE,IAAI,OAAO,EAAE,CAAC;gBACZ,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;oBACzB,IAAI,EAAE,CAAC,EAAE,KAAK,MAAM;wBAAE,QAAQ,IAAI,EAAE,CAAC,KAAK,CAAC;oBAC3C,IAAI,EAAE,CAAC,EAAE,KAAK,OAAO;wBAAE,SAAS,IAAI,EAAE,CAAC,KAAK,CAAC;gBAC/C,CAAC;YACH,CAAC;YAED,OAAO;gBACL,WAAW,EAAE,SAAS,CAAC,YAAY,CAAC,KAAK;gBACzC,WAAW,EAAE,SAAS,CAAC,YAAY,CAAC,KAAK;gBACzC,UAAU;gBACV,SAAS;gBACT,SAAS;gBACT,QAAQ;gBACR,SAAS;aACV,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA/mBD,wCA+mBC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KATASHIRO Sandbox Package
|
|
3
|
+
*
|
|
4
|
+
* @fileoverview REQ-007: コード実行サンドボックス
|
|
5
|
+
* @module @nahisaho/katashiro-sandbox
|
|
6
|
+
* @since 0.4.0
|
|
7
|
+
*/
|
|
8
|
+
export type { SandboxRuntime, SupportedLanguage, ExecutionStatus, SandboxConfig, DockerConfig, ExecutionRequest, FileOutput, ExecutionResult, ExecutionError, SecurityPolicy, SandboxEventType, SandboxEvent, SandboxEventListener, ContainerInfo, ResourceStats, } from './types';
|
|
9
|
+
export { DEFAULT_SANDBOX_CONFIG, DEFAULT_DOCKER_CONFIG, DEFAULT_DOCKER_IMAGES, DEFAULT_SECURITY_POLICY, } from './types';
|
|
10
|
+
export { DockerExecutor, SandboxError } from './docker-executor';
|
|
11
|
+
export { LocalExecutor } from './local-executor';
|
|
12
|
+
export { SandboxFactory, type ISandbox, executeCode, executeBash, executePython, executeJavaScript, executeTypeScript, } from './sandbox';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EACL,cAAc,EACd,KAAK,QAAQ,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* KATASHIRO Sandbox Package
|
|
4
|
+
*
|
|
5
|
+
* @fileoverview REQ-007: コード実行サンドボックス
|
|
6
|
+
* @module @nahisaho/katashiro-sandbox
|
|
7
|
+
* @since 0.4.0
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.executeTypeScript = exports.executeJavaScript = exports.executePython = exports.executeBash = exports.executeCode = exports.SandboxFactory = exports.LocalExecutor = exports.SandboxError = exports.DockerExecutor = exports.DEFAULT_SECURITY_POLICY = exports.DEFAULT_DOCKER_IMAGES = exports.DEFAULT_DOCKER_CONFIG = exports.DEFAULT_SANDBOX_CONFIG = void 0;
|
|
11
|
+
// 定数
|
|
12
|
+
var types_1 = require("./types");
|
|
13
|
+
Object.defineProperty(exports, "DEFAULT_SANDBOX_CONFIG", { enumerable: true, get: function () { return types_1.DEFAULT_SANDBOX_CONFIG; } });
|
|
14
|
+
Object.defineProperty(exports, "DEFAULT_DOCKER_CONFIG", { enumerable: true, get: function () { return types_1.DEFAULT_DOCKER_CONFIG; } });
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_DOCKER_IMAGES", { enumerable: true, get: function () { return types_1.DEFAULT_DOCKER_IMAGES; } });
|
|
16
|
+
Object.defineProperty(exports, "DEFAULT_SECURITY_POLICY", { enumerable: true, get: function () { return types_1.DEFAULT_SECURITY_POLICY; } });
|
|
17
|
+
// Docker Executor
|
|
18
|
+
var docker_executor_1 = require("./docker-executor");
|
|
19
|
+
Object.defineProperty(exports, "DockerExecutor", { enumerable: true, get: function () { return docker_executor_1.DockerExecutor; } });
|
|
20
|
+
Object.defineProperty(exports, "SandboxError", { enumerable: true, get: function () { return docker_executor_1.SandboxError; } });
|
|
21
|
+
// Local Executor
|
|
22
|
+
var local_executor_1 = require("./local-executor");
|
|
23
|
+
Object.defineProperty(exports, "LocalExecutor", { enumerable: true, get: function () { return local_executor_1.LocalExecutor; } });
|
|
24
|
+
// Sandbox Factory & Interface
|
|
25
|
+
var sandbox_1 = require("./sandbox");
|
|
26
|
+
Object.defineProperty(exports, "SandboxFactory", { enumerable: true, get: function () { return sandbox_1.SandboxFactory; } });
|
|
27
|
+
Object.defineProperty(exports, "executeCode", { enumerable: true, get: function () { return sandbox_1.executeCode; } });
|
|
28
|
+
Object.defineProperty(exports, "executeBash", { enumerable: true, get: function () { return sandbox_1.executeBash; } });
|
|
29
|
+
Object.defineProperty(exports, "executePython", { enumerable: true, get: function () { return sandbox_1.executePython; } });
|
|
30
|
+
Object.defineProperty(exports, "executeJavaScript", { enumerable: true, get: function () { return sandbox_1.executeJavaScript; } });
|
|
31
|
+
Object.defineProperty(exports, "executeTypeScript", { enumerable: true, get: function () { return sandbox_1.executeTypeScript; } });
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAqBH,KAAK;AACL,iCAKiB;AAJf,+GAAA,sBAAsB,OAAA;AACtB,8GAAA,qBAAqB,OAAA;AACrB,8GAAA,qBAAqB,OAAA;AACrB,gHAAA,uBAAuB,OAAA;AAGzB,kBAAkB;AAClB,qDAAiE;AAAxD,iHAAA,cAAc,OAAA;AAAE,+GAAA,YAAY,OAAA;AAErC,iBAAiB;AACjB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AAEtB,8BAA8B;AAC9B,qCAQmB;AAPjB,yGAAA,cAAc,OAAA;AAEd,sGAAA,WAAW,OAAA;AACX,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AACb,4GAAA,iBAAiB,OAAA;AACjB,4GAAA,iBAAiB,OAAA"}
|