microsandbox 0.1.0 → 0.1.1
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 +121 -16
- package/dist/base-sandbox.d.ts +91 -0
- package/dist/base-sandbox.js +264 -0
- package/dist/base-sandbox.js.map +1 -0
- package/dist/command-execution.d.ts +59 -0
- package/dist/command-execution.js +102 -0
- package/dist/command-execution.js.map +1 -0
- package/dist/command.d.ts +24 -0
- package/dist/command.js +84 -0
- package/dist/command.js.map +1 -0
- package/dist/execution.d.ts +52 -0
- package/dist/execution.js +103 -0
- package/dist/execution.js.map +1 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.js +20 -14
- package/dist/index.js.map +1 -0
- package/dist/metrics.d.ts +69 -0
- package/dist/metrics.js +142 -0
- package/dist/metrics.js.map +1 -0
- package/dist/node-sandbox.d.ts +32 -0
- package/dist/node-sandbox.js +92 -0
- package/dist/node-sandbox.js.map +1 -0
- package/dist/python-sandbox.d.ts +32 -0
- package/dist/python-sandbox.js +92 -0
- package/dist/python-sandbox.js.map +1 -0
- package/dist/types.d.ts +110 -0
- package/dist/types.js +88 -0
- package/dist/types.js.map +1 -0
- package/package.json +23 -4
|
@@ -0,0 +1,92 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,OAAO,GA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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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,OAAO,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,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* 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
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QAC7B,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,OAAO,CAAC,OAAe;QACrB,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACF;AAzED,sDAyEC;AAED;;GAEG;AACH,IAAiB,cAAc,CAM9B;AAND,WAAiB,cAAc;IAC7B;;OAEG;IACU,sBAAO,GAAG,GAA0B,EAAE,CACjD,IAAI,qBAAqB,EAAE,CAAC;AAChC,CAAC,EANgB,cAAc,8BAAd,cAAc,QAM9B"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "microsandbox",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "TypeScript SDK for creating and managing secure sandboxes for code execution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=14.0.0"
|
|
12
|
+
},
|
|
10
13
|
"scripts": {
|
|
11
14
|
"build": "tsc",
|
|
12
15
|
"test": "jest",
|
|
13
16
|
"lint": "eslint src --ext .ts",
|
|
14
|
-
"prepare": "npm run build"
|
|
17
|
+
"prepare": "npm run build",
|
|
18
|
+
"example:node": "ts-node examples/node.ts",
|
|
19
|
+
"example:python": "ts-node examples/python.ts",
|
|
20
|
+
"example:command": "ts-node examples/command.ts",
|
|
21
|
+
"example:metrics": "ts-node examples/metrics.ts"
|
|
15
22
|
},
|
|
16
23
|
"keywords": [
|
|
17
24
|
"microsandbox",
|
|
18
|
-
"sdk"
|
|
25
|
+
"sdk",
|
|
26
|
+
"sandbox",
|
|
27
|
+
"security",
|
|
28
|
+
"code-execution",
|
|
29
|
+
"typescript"
|
|
19
30
|
],
|
|
20
31
|
"author": "Microsandbox Team <team@microsandbox.dev>",
|
|
21
32
|
"license": "Apache-2.0",
|
|
@@ -30,9 +41,17 @@
|
|
|
30
41
|
"devDependencies": {
|
|
31
42
|
"@types/jest": "^29.5.0",
|
|
32
43
|
"@types/node": "^18.15.0",
|
|
44
|
+
"@types/node-fetch": "^2.6.4",
|
|
45
|
+
"@types/uuid": "^9.0.1",
|
|
33
46
|
"eslint": "^8.36.0",
|
|
34
47
|
"jest": "^29.5.0",
|
|
35
48
|
"ts-jest": "^29.1.0",
|
|
49
|
+
"ts-node": "^10.9.1",
|
|
36
50
|
"typescript": "^5.0.2"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"dotenv": "^16.3.1",
|
|
54
|
+
"node-fetch": "^2.6.12",
|
|
55
|
+
"uuid": "^9.0.0"
|
|
37
56
|
}
|
|
38
57
|
}
|