microsandbox 0.1.1 → 0.3.7
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 +333 -84
- package/index.cjs +609 -0
- package/index.d.cts +751 -0
- package/index.mjs +21 -0
- package/package.json +31 -48
- package/postinstall.js +194 -0
- package/dist/base-sandbox.d.ts +0 -91
- package/dist/base-sandbox.js +0 -264
- package/dist/base-sandbox.js.map +0 -1
- package/dist/command-execution.d.ts +0 -59
- package/dist/command-execution.js +0 -102
- package/dist/command-execution.js.map +0 -1
- package/dist/command.d.ts +0 -24
- package/dist/command.js +0 -84
- package/dist/command.js.map +0 -1
- package/dist/execution.d.ts +0 -52
- package/dist/execution.js +0 -103
- package/dist/execution.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -25
- package/dist/index.js.map +0 -1
- package/dist/metrics.d.ts +0 -69
- package/dist/metrics.js +0 -142
- package/dist/metrics.js.map +0 -1
- package/dist/node-sandbox.d.ts +0 -32
- package/dist/node-sandbox.js +0 -92
- package/dist/node-sandbox.js.map +0 -1
- package/dist/python-sandbox.d.ts +0 -32
- package/dist/python-sandbox.js +0 -92
- package/dist/python-sandbox.js.map +0 -1
- package/dist/types.d.ts +0 -110
- package/dist/types.js +0 -88
- package/dist/types.js.map +0 -1
package/dist/metrics.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Metrics interface for the Microsandbox TypeScript SDK.
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Metrics = void 0;
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
-
class Metrics {
|
|
13
|
-
/**
|
|
14
|
-
* Initialize the metrics instance.
|
|
15
|
-
*
|
|
16
|
-
* @param sandboxInstance - The sandbox instance this metrics object belongs to
|
|
17
|
-
*/
|
|
18
|
-
constructor(sandboxInstance) {
|
|
19
|
-
this.sandbox = sandboxInstance;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Internal method to fetch current metrics from the server.
|
|
23
|
-
*
|
|
24
|
-
* @returns A dictionary containing the metrics data for the sandbox
|
|
25
|
-
* @throws Error if the request to the server fails
|
|
26
|
-
*/
|
|
27
|
-
async getMetrics() {
|
|
28
|
-
if (!this.sandbox.isStarted) {
|
|
29
|
-
throw new Error("Sandbox is not started. Call start() first.");
|
|
30
|
-
}
|
|
31
|
-
const headers = {
|
|
32
|
-
"Content-Type": "application/json",
|
|
33
|
-
};
|
|
34
|
-
if (this.sandbox.apiKey) {
|
|
35
|
-
headers["Authorization"] = `Bearer ${this.sandbox.apiKey}`;
|
|
36
|
-
}
|
|
37
|
-
// Prepare the request data
|
|
38
|
-
const requestData = {
|
|
39
|
-
jsonrpc: "2.0",
|
|
40
|
-
method: "sandbox.metrics.get",
|
|
41
|
-
params: {
|
|
42
|
-
namespace: this.sandbox.namespace,
|
|
43
|
-
sandbox: this.sandbox.name,
|
|
44
|
-
},
|
|
45
|
-
id: (0, uuid_1.v4)(),
|
|
46
|
-
};
|
|
47
|
-
try {
|
|
48
|
-
const response = await (0, node_fetch_1.default)(`${this.sandbox.serverUrl}/api/v1/rpc`, {
|
|
49
|
-
method: "POST",
|
|
50
|
-
headers,
|
|
51
|
-
body: JSON.stringify(requestData),
|
|
52
|
-
});
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
const errorText = await response.text();
|
|
55
|
-
throw new Error(`Failed to get sandbox metrics: ${errorText}`);
|
|
56
|
-
}
|
|
57
|
-
const responseData = await response.json();
|
|
58
|
-
if ("error" in responseData) {
|
|
59
|
-
throw new Error(`Failed to get sandbox metrics: ${responseData.error.message}`);
|
|
60
|
-
}
|
|
61
|
-
const result = responseData.result || {};
|
|
62
|
-
const sandboxes = result.sandboxes || [];
|
|
63
|
-
// We expect exactly one sandbox in the response (our own)
|
|
64
|
-
if (!sandboxes.length) {
|
|
65
|
-
return {};
|
|
66
|
-
}
|
|
67
|
-
// Return the first (and should be only) sandbox data
|
|
68
|
-
return sandboxes[0];
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
if (e instanceof Error) {
|
|
72
|
-
throw new Error(`Failed to get sandbox metrics: ${e.message}`);
|
|
73
|
-
}
|
|
74
|
-
throw new Error("Failed to get sandbox metrics: Unknown error");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get all metrics for the current sandbox.
|
|
79
|
-
*
|
|
80
|
-
* @returns A dictionary containing all metrics for the sandbox:
|
|
81
|
-
* {
|
|
82
|
-
* "name": string,
|
|
83
|
-
* "namespace": string,
|
|
84
|
-
* "running": boolean,
|
|
85
|
-
* "cpu_usage": number | null,
|
|
86
|
-
* "memory_usage": number | null,
|
|
87
|
-
* "disk_usage": number | null
|
|
88
|
-
* }
|
|
89
|
-
*
|
|
90
|
-
* @throws Error if the sandbox is not started or if the request fails
|
|
91
|
-
*/
|
|
92
|
-
async all() {
|
|
93
|
-
return await this.getMetrics();
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Get CPU usage percentage for the current sandbox.
|
|
97
|
-
*
|
|
98
|
-
* @returns CPU usage as a percentage (0-100) or undefined if not available.
|
|
99
|
-
* May return 0.0 for idle sandboxes or when metrics are not precise.
|
|
100
|
-
*
|
|
101
|
-
* @throws Error if the sandbox is not started or if the request fails
|
|
102
|
-
*/
|
|
103
|
-
async cpu() {
|
|
104
|
-
const metrics = await this.getMetrics();
|
|
105
|
-
return metrics.cpu_usage;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get memory usage for the current sandbox.
|
|
109
|
-
*
|
|
110
|
-
* @returns Memory usage in MiB or undefined if not available
|
|
111
|
-
*
|
|
112
|
-
* @throws Error if the sandbox is not started or if the request fails
|
|
113
|
-
*/
|
|
114
|
-
async memory() {
|
|
115
|
-
const metrics = await this.getMetrics();
|
|
116
|
-
return metrics.memory_usage;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Get disk usage for the current sandbox.
|
|
120
|
-
*
|
|
121
|
-
* @returns Disk usage in bytes or undefined if not available
|
|
122
|
-
*
|
|
123
|
-
* @throws Error if the sandbox is not started or if the request fails
|
|
124
|
-
*/
|
|
125
|
-
async disk() {
|
|
126
|
-
const metrics = await this.getMetrics();
|
|
127
|
-
return metrics.disk_usage;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Check if the sandbox is currently running.
|
|
131
|
-
*
|
|
132
|
-
* @returns True if the sandbox is running, False otherwise
|
|
133
|
-
*
|
|
134
|
-
* @throws Error if the request to the server fails
|
|
135
|
-
*/
|
|
136
|
-
async isRunning() {
|
|
137
|
-
const metrics = await this.getMetrics();
|
|
138
|
-
return metrics.running || false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.Metrics = Metrics;
|
|
142
|
-
//# sourceMappingURL=metrics.js.map
|
package/dist/metrics.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,+BAAoC;AACpC,4DAA+B;AAI/B,MAAa,OAAO;IAGlB;;;;OAIG;IACH,YAAY,eAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,UAAU;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;S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O,EAAE,CAAC;YACZ,CAAC;YAED,qDAAqD;YACrD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,GAAG;QACP,OAAO,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG;QACP,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,SAAS,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM;QACV,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,YAAY,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,UAAU,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;IAClC,CAAC;CACF;AAnJD,0BAmJC"}
|
package/dist/node-sandbox.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js-specific sandbox implementation for the Microsandbox TypeScript SDK.
|
|
3
|
-
*/
|
|
4
|
-
import { BaseSandbox } from "./base-sandbox";
|
|
5
|
-
import { Execution } from "./execution";
|
|
6
|
-
import { SandboxOptions } from "./types";
|
|
7
|
-
export declare class NodeSandbox extends BaseSandbox {
|
|
8
|
-
/**
|
|
9
|
-
* Get the default Docker image for Node.js sandbox.
|
|
10
|
-
*
|
|
11
|
-
* @returns A string containing the Docker image name and tag
|
|
12
|
-
*/
|
|
13
|
-
getDefaultImage(): Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Execute JavaScript code in the sandbox.
|
|
16
|
-
*
|
|
17
|
-
* @param code - JavaScript code to execute
|
|
18
|
-
* @param options - Optional execution options like timeout
|
|
19
|
-
* @returns An Execution object that represents the executed code
|
|
20
|
-
* @throws Error if the sandbox is not started or execution fails
|
|
21
|
-
*/
|
|
22
|
-
run(code: string, options?: {
|
|
23
|
-
timeout?: number;
|
|
24
|
-
}): Promise<Execution>;
|
|
25
|
-
/**
|
|
26
|
-
* Create and initialize a new NodeSandbox instance.
|
|
27
|
-
*
|
|
28
|
-
* @param options - Configuration options for the sandbox
|
|
29
|
-
* @returns A Promise resolving to a new NodeSandbox instance
|
|
30
|
-
*/
|
|
31
|
-
static create(options?: SandboxOptions): Promise<NodeSandbox>;
|
|
32
|
-
}
|
package/dist/node-sandbox.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Node.js-specific sandbox implementation for the Microsandbox TypeScript SDK.
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.NodeSandbox = void 0;
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
-
const base_sandbox_1 = require("./base-sandbox");
|
|
13
|
-
const execution_1 = require("./execution");
|
|
14
|
-
class NodeSandbox extends base_sandbox_1.BaseSandbox {
|
|
15
|
-
/**
|
|
16
|
-
* Get the default Docker image for Node.js sandbox.
|
|
17
|
-
*
|
|
18
|
-
* @returns A string containing the Docker image name and tag
|
|
19
|
-
*/
|
|
20
|
-
async getDefaultImage() {
|
|
21
|
-
return "microsandbox/node";
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Execute JavaScript code in the sandbox.
|
|
25
|
-
*
|
|
26
|
-
* @param code - JavaScript code to execute
|
|
27
|
-
* @param options - Optional execution options like timeout
|
|
28
|
-
* @returns An Execution object that represents the executed code
|
|
29
|
-
* @throws Error if the sandbox is not started or execution fails
|
|
30
|
-
*/
|
|
31
|
-
async run(code, options) {
|
|
32
|
-
if (!this._isStarted) {
|
|
33
|
-
throw new Error("Sandbox is not started. Call start() first.");
|
|
34
|
-
}
|
|
35
|
-
const headers = {
|
|
36
|
-
"Content-Type": "application/json",
|
|
37
|
-
};
|
|
38
|
-
if (this._apiKey) {
|
|
39
|
-
headers["Authorization"] = `Bearer ${this._apiKey}`;
|
|
40
|
-
}
|
|
41
|
-
const requestData = {
|
|
42
|
-
jsonrpc: "2.0",
|
|
43
|
-
method: "sandbox.repl.run",
|
|
44
|
-
params: {
|
|
45
|
-
sandbox: this._name,
|
|
46
|
-
namespace: this._namespace,
|
|
47
|
-
language: "nodejs",
|
|
48
|
-
code,
|
|
49
|
-
},
|
|
50
|
-
id: (0, uuid_1.v4)(),
|
|
51
|
-
};
|
|
52
|
-
// Add timeout if specified in options
|
|
53
|
-
if (options?.timeout !== undefined) {
|
|
54
|
-
requestData.params.timeout = options.timeout;
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const response = await (0, node_fetch_1.default)(`${this._serverUrl}/api/v1/rpc`, {
|
|
58
|
-
method: "POST",
|
|
59
|
-
headers,
|
|
60
|
-
body: JSON.stringify(requestData),
|
|
61
|
-
});
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
const errorText = await response.text();
|
|
64
|
-
throw new Error(`Failed to execute code: ${errorText}`);
|
|
65
|
-
}
|
|
66
|
-
const responseData = await response.json();
|
|
67
|
-
if ("error" in responseData) {
|
|
68
|
-
throw new Error(`Failed to execute code: ${responseData.error.message}`);
|
|
69
|
-
}
|
|
70
|
-
const result = responseData.result || {};
|
|
71
|
-
// Create and return an Execution object with the output data
|
|
72
|
-
return new execution_1.Execution(result);
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
if (e instanceof Error) {
|
|
76
|
-
throw new Error(`Failed to execute code: ${e.message}`);
|
|
77
|
-
}
|
|
78
|
-
throw new Error("Failed to execute code: Unknown error");
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Create and initialize a new NodeSandbox instance.
|
|
83
|
-
*
|
|
84
|
-
* @param options - Configuration options for the sandbox
|
|
85
|
-
* @returns A Promise resolving to a new NodeSandbox instance
|
|
86
|
-
*/
|
|
87
|
-
static async create(options) {
|
|
88
|
-
return base_sandbox_1.BaseSandbox.createBase(NodeSandbox, options);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.NodeSandbox = NodeSandbox;
|
|
92
|
-
//# sourceMappingURL=node-sandbox.js.map
|
package/dist/node-sandbox.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node-sandbox.js","sourceRoot":"","sources":["../src/node-sandbox.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,+BAAoC;AACpC,4DAA+B;AAE/B,iDAA6C;AAC7C,2CAAwC;AAGxC,MAAa,WAAY,SAAQ,0BAAW;IAC1C;;;;OAIG;IACH,KAAK,CAAC,eAAe;QACnB,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,OAA8B;QACpD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,6CAA6C,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,MAAM,GAAG,YAAY,CAAC,MAAM,IAAI,EAAE,CAAC;YAEzC,6DAA6D;YAC7D,OAAO,IAAI,qBAAS,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1D,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAwB;QAC1C,OAAO,0BAAW,CAAC,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACF;AApGD,kCAoGC"}
|
package/dist/python-sandbox.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Python-specific sandbox implementation for the Microsandbox TypeScript SDK.
|
|
3
|
-
*/
|
|
4
|
-
import { BaseSandbox } from "./base-sandbox";
|
|
5
|
-
import { Execution } from "./execution";
|
|
6
|
-
import { SandboxOptions } from "./types";
|
|
7
|
-
export declare class PythonSandbox extends BaseSandbox {
|
|
8
|
-
/**
|
|
9
|
-
* Get the default Docker image for Python sandbox.
|
|
10
|
-
*
|
|
11
|
-
* @returns A string containing the Docker image name and tag
|
|
12
|
-
*/
|
|
13
|
-
getDefaultImage(): Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Execute Python code in the sandbox.
|
|
16
|
-
*
|
|
17
|
-
* @param code - Python code to execute
|
|
18
|
-
* @param options - Optional execution options like timeout
|
|
19
|
-
* @returns An Execution object that represents the executed code
|
|
20
|
-
* @throws Error if the sandbox is not started or execution fails
|
|
21
|
-
*/
|
|
22
|
-
run(code: string, options?: {
|
|
23
|
-
timeout?: number;
|
|
24
|
-
}): Promise<Execution>;
|
|
25
|
-
/**
|
|
26
|
-
* Create and initialize a new PythonSandbox instance.
|
|
27
|
-
*
|
|
28
|
-
* @param options - Configuration options for the sandbox
|
|
29
|
-
* @returns A Promise resolving to a new PythonSandbox instance
|
|
30
|
-
*/
|
|
31
|
-
static create(options?: SandboxOptions): Promise<PythonSandbox>;
|
|
32
|
-
}
|
package/dist/python-sandbox.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Python-specific sandbox implementation for the Microsandbox TypeScript SDK.
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.PythonSandbox = void 0;
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
-
const base_sandbox_1 = require("./base-sandbox");
|
|
13
|
-
const execution_1 = require("./execution");
|
|
14
|
-
class PythonSandbox extends base_sandbox_1.BaseSandbox {
|
|
15
|
-
/**
|
|
16
|
-
* Get the default Docker image for Python sandbox.
|
|
17
|
-
*
|
|
18
|
-
* @returns A string containing the Docker image name and tag
|
|
19
|
-
*/
|
|
20
|
-
async getDefaultImage() {
|
|
21
|
-
return "microsandbox/python";
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Execute Python code in the sandbox.
|
|
25
|
-
*
|
|
26
|
-
* @param code - Python code to execute
|
|
27
|
-
* @param options - Optional execution options like timeout
|
|
28
|
-
* @returns An Execution object that represents the executed code
|
|
29
|
-
* @throws Error if the sandbox is not started or execution fails
|
|
30
|
-
*/
|
|
31
|
-
async run(code, options) {
|
|
32
|
-
if (!this._isStarted) {
|
|
33
|
-
throw new Error("Sandbox is not started. Call start() first.");
|
|
34
|
-
}
|
|
35
|
-
const headers = {
|
|
36
|
-
"Content-Type": "application/json",
|
|
37
|
-
};
|
|
38
|
-
if (this._apiKey) {
|
|
39
|
-
headers["Authorization"] = `Bearer ${this._apiKey}`;
|
|
40
|
-
}
|
|
41
|
-
const requestData = {
|
|
42
|
-
jsonrpc: "2.0",
|
|
43
|
-
method: "sandbox.repl.run",
|
|
44
|
-
params: {
|
|
45
|
-
sandbox: this._name,
|
|
46
|
-
namespace: this._namespace,
|
|
47
|
-
language: "python",
|
|
48
|
-
code,
|
|
49
|
-
},
|
|
50
|
-
id: (0, uuid_1.v4)(),
|
|
51
|
-
};
|
|
52
|
-
// Add timeout if specified in options
|
|
53
|
-
if (options?.timeout !== undefined) {
|
|
54
|
-
requestData.params.timeout = options.timeout;
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const response = await (0, node_fetch_1.default)(`${this._serverUrl}/api/v1/rpc`, {
|
|
58
|
-
method: "POST",
|
|
59
|
-
headers,
|
|
60
|
-
body: JSON.stringify(requestData),
|
|
61
|
-
});
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
const errorText = await response.text();
|
|
64
|
-
throw new Error(`Failed to execute code: ${errorText}`);
|
|
65
|
-
}
|
|
66
|
-
const responseData = await response.json();
|
|
67
|
-
if ("error" in responseData) {
|
|
68
|
-
throw new Error(`Failed to execute code: ${responseData.error.message}`);
|
|
69
|
-
}
|
|
70
|
-
const result = responseData.result || {};
|
|
71
|
-
// Create and return an Execution object with the output data
|
|
72
|
-
return new execution_1.Execution(result);
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
if (e instanceof Error) {
|
|
76
|
-
throw new Error(`Failed to execute code: ${e.message}`);
|
|
77
|
-
}
|
|
78
|
-
throw new Error("Failed to execute code: Unknown error");
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Create and initialize a new PythonSandbox instance.
|
|
83
|
-
*
|
|
84
|
-
* @param options - Configuration options for the sandbox
|
|
85
|
-
* @returns A Promise resolving to a new PythonSandbox instance
|
|
86
|
-
*/
|
|
87
|
-
static async create(options) {
|
|
88
|
-
return base_sandbox_1.BaseSandbox.createBase(PythonSandbox, options);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.PythonSandbox = PythonSandbox;
|
|
92
|
-
//# sourceMappingURL=python-sandbox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"python-sandbox.js","sourceRoot":"","sources":["../src/python-sandbox.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,+BAAoC;AACpC,4DAA+B;AAE/B,iDAA6C;AAC7C,2CAAwC;AAGxC,MAAa,aAAc,SAAQ,0BAAW;IAC5C;;;;OAIG;IACH,KAAK,CAAC,eAAe;QACnB,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,OAA8B;QACpD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QAEF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,IAAI,CAAC,OAAO,EAAE,CAAC;QACtD,CAAC;QAED,MAAM,WAAW,GAWb;YACF,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,kBAAkB;YAC1B,MAAM,EAAE;gBACN,OAAO,EAAE,IAAI,CAAC,KAAK;gBACnB,SAAS,EAAE,IAAI,CAAC,UAAU;gBAC1B,QAAQ,EAAE,QAAQ;gBAClB,IAAI;aACL;YACD,EAAE,EAAE,IAAA,SAAM,GAAE;SACb,CAAC;QAEF,sCAAsC;QACtC,IAAI,OAAO,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;YACnC,WAAW,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO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-
/**
|
|
2
|
-
* Common types and interfaces for the Microsandbox TypeScript SDK
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Options for creating a sandbox
|
|
6
|
-
*/
|
|
7
|
-
export interface SandboxOptions {
|
|
8
|
-
/**
|
|
9
|
-
* URL of the Microsandbox server
|
|
10
|
-
*/
|
|
11
|
-
serverUrl?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Namespace for the sandbox
|
|
14
|
-
*/
|
|
15
|
-
namespace?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Name for the sandbox
|
|
18
|
-
*/
|
|
19
|
-
name?: string;
|
|
20
|
-
/**
|
|
21
|
-
* API key for Microsandbox server authentication
|
|
22
|
-
*/
|
|
23
|
-
apiKey?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Docker image to use for the sandbox
|
|
26
|
-
*/
|
|
27
|
-
image?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Memory limit in MB
|
|
30
|
-
*/
|
|
31
|
-
memory?: number;
|
|
32
|
-
/**
|
|
33
|
-
* CPU limit (will be rounded to nearest integer)
|
|
34
|
-
*/
|
|
35
|
-
cpus?: number;
|
|
36
|
-
/**
|
|
37
|
-
* Maximum time in seconds to wait for the sandbox to start
|
|
38
|
-
*/
|
|
39
|
-
timeout?: number;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Builder pattern for SandboxOptions
|
|
43
|
-
*/
|
|
44
|
-
export declare class SandboxOptionsBuilder {
|
|
45
|
-
private options;
|
|
46
|
-
/**
|
|
47
|
-
* Set server URL
|
|
48
|
-
*/
|
|
49
|
-
serverUrl(serverUrl: string): SandboxOptionsBuilder;
|
|
50
|
-
/**
|
|
51
|
-
* Set namespace
|
|
52
|
-
*/
|
|
53
|
-
namespace(namespace: string): SandboxOptionsBuilder;
|
|
54
|
-
/**
|
|
55
|
-
* Set sandbox name
|
|
56
|
-
*/
|
|
57
|
-
name(name: string): SandboxOptionsBuilder;
|
|
58
|
-
/**
|
|
59
|
-
* Set API key
|
|
60
|
-
*/
|
|
61
|
-
apiKey(apiKey: string): SandboxOptionsBuilder;
|
|
62
|
-
/**
|
|
63
|
-
* Set Docker image
|
|
64
|
-
*/
|
|
65
|
-
image(image: string): SandboxOptionsBuilder;
|
|
66
|
-
/**
|
|
67
|
-
* Set memory limit
|
|
68
|
-
*/
|
|
69
|
-
memory(memory: number): SandboxOptionsBuilder;
|
|
70
|
-
/**
|
|
71
|
-
* Set CPU limit
|
|
72
|
-
*/
|
|
73
|
-
cpus(cpus: number): SandboxOptionsBuilder;
|
|
74
|
-
/**
|
|
75
|
-
* Set timeout
|
|
76
|
-
*/
|
|
77
|
-
timeout(timeout: number): SandboxOptionsBuilder;
|
|
78
|
-
/**
|
|
79
|
-
* Build SandboxOptions object
|
|
80
|
-
*/
|
|
81
|
-
build(): SandboxOptions;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Namespace for SandboxOptions
|
|
85
|
-
*/
|
|
86
|
-
export declare namespace SandboxOptions {
|
|
87
|
-
/**
|
|
88
|
-
* Create a builder for SandboxOptions
|
|
89
|
-
*/
|
|
90
|
-
const builder: () => SandboxOptionsBuilder;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Output line from sandbox execution
|
|
94
|
-
*/
|
|
95
|
-
export interface OutputLine {
|
|
96
|
-
stream: "stdout" | "stderr";
|
|
97
|
-
text: string;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Output data from sandbox execution
|
|
101
|
-
*/
|
|
102
|
-
export interface OutputData {
|
|
103
|
-
output?: OutputLine[];
|
|
104
|
-
status?: string;
|
|
105
|
-
language?: string;
|
|
106
|
-
success?: boolean;
|
|
107
|
-
exit_code?: number;
|
|
108
|
-
command?: string;
|
|
109
|
-
args?: string[];
|
|
110
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Common types and interfaces for the Microsandbox TypeScript SDK
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SandboxOptions = exports.SandboxOptionsBuilder = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Builder pattern for SandboxOptions
|
|
9
|
-
*/
|
|
10
|
-
class SandboxOptionsBuilder {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.options = {};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Set server URL
|
|
16
|
-
*/
|
|
17
|
-
serverUrl(serverUrl) {
|
|
18
|
-
this.options.serverUrl = serverUrl;
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Set namespace
|
|
23
|
-
*/
|
|
24
|
-
namespace(namespace) {
|
|
25
|
-
this.options.namespace = namespace;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Set sandbox name
|
|
30
|
-
*/
|
|
31
|
-
name(name) {
|
|
32
|
-
this.options.name = name;
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Set API key
|
|
37
|
-
*/
|
|
38
|
-
apiKey(apiKey) {
|
|
39
|
-
this.options.apiKey = apiKey;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Set Docker image
|
|
44
|
-
*/
|
|
45
|
-
image(image) {
|
|
46
|
-
this.options.image = image;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Set memory limit
|
|
51
|
-
*/
|
|
52
|
-
memory(memory) {
|
|
53
|
-
this.options.memory = memory;
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Set CPU limit
|
|
58
|
-
*/
|
|
59
|
-
cpus(cpus) {
|
|
60
|
-
this.options.cpus = cpus;
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Set timeout
|
|
65
|
-
*/
|
|
66
|
-
timeout(timeout) {
|
|
67
|
-
this.options.timeout = timeout;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Build SandboxOptions object
|
|
72
|
-
*/
|
|
73
|
-
build() {
|
|
74
|
-
return { ...this.options };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.SandboxOptionsBuilder = SandboxOptionsBuilder;
|
|
78
|
-
/**
|
|
79
|
-
* Namespace for SandboxOptions
|
|
80
|
-
*/
|
|
81
|
-
var SandboxOptions;
|
|
82
|
-
(function (SandboxOptions) {
|
|
83
|
-
/**
|
|
84
|
-
* Create a builder for SandboxOptions
|
|
85
|
-
*/
|
|
86
|
-
SandboxOptions.builder = () => new SandboxOptionsBuilder();
|
|
87
|
-
})(SandboxOptions || (exports.SandboxOptions = SandboxOptions = {}));
|
|
88
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AA+CH;;GAEG;AACH,MAAa,qBAAqB;IAAlC;QACU,YAAO,GAAmB,EAAE,CAAC;IAwEvC,CAAC;IAtEC;;OAEG;IACH,SAAS,CAAC,SAAiB;QACzB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,SAAiB;QACzB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,IAAY;QACf,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAc;QACnB,IAAI,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