@agentick/sandbox 0.2.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 +251 -0
- package/dist/component.d.ts +43 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +41 -0
- package/dist/component.js.map +1 -0
- package/dist/context.d.ts +26 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +32 -0
- package/dist/context.js.map +1 -0
- package/dist/edit.d.ts +62 -0
- package/dist/edit.d.ts.map +1 -0
- package/dist/edit.js +270 -0
- package/dist/edit.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +29 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +49 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools.d.ts +37 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +93 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +156 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +65 -0
- package/src/index.ts +40 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox Contract Types
|
|
3
|
+
*
|
|
4
|
+
* All types for the sandbox abstraction layer.
|
|
5
|
+
* Provider adapters (@agentick/sandbox-local, @agentick/sandbox-docker, etc.)
|
|
6
|
+
* implement SandboxProvider.
|
|
7
|
+
*/
|
|
8
|
+
import type { Edit, EditResult } from "./edit";
|
|
9
|
+
export interface Sandbox {
|
|
10
|
+
/** Unique sandbox instance ID. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** Absolute path to the workspace root inside the sandbox. */
|
|
13
|
+
readonly workspacePath: string;
|
|
14
|
+
/** Execute a shell command. */
|
|
15
|
+
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
16
|
+
/** Read a file from the sandbox filesystem. */
|
|
17
|
+
readFile(path: string): Promise<string>;
|
|
18
|
+
/** Write a file to the sandbox filesystem. */
|
|
19
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
20
|
+
/** Apply surgical edits to a file. */
|
|
21
|
+
editFile(path: string, edits: Edit[]): Promise<EditResult>;
|
|
22
|
+
/** Tear down the sandbox and release resources. */
|
|
23
|
+
destroy(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface SandboxProvider {
|
|
26
|
+
/** Provider name (e.g. "local", "docker", "e2b"). */
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/** Create a new sandbox instance. */
|
|
29
|
+
create(options: SandboxCreateOptions): Promise<Sandbox>;
|
|
30
|
+
/** Restore a sandbox from a snapshot. */
|
|
31
|
+
restore?(snapshot: SandboxSnapshot): Promise<Sandbox>;
|
|
32
|
+
/** Destroy a sandbox (provider-level cleanup). */
|
|
33
|
+
destroy?(sandbox: Sandbox): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export interface SandboxCreateOptions {
|
|
36
|
+
/** Session ID for associating the sandbox with a session. */
|
|
37
|
+
sessionId?: string;
|
|
38
|
+
/** Workspace directory path, or true to auto-create a temp directory. */
|
|
39
|
+
workspace?: string | true;
|
|
40
|
+
/** Host↔sandbox path mappings. */
|
|
41
|
+
mounts?: Mount[];
|
|
42
|
+
/** Advisory permissions. */
|
|
43
|
+
permissions?: Permissions;
|
|
44
|
+
/** Environment variables. */
|
|
45
|
+
env?: Record<string, string>;
|
|
46
|
+
/** Resource constraints. */
|
|
47
|
+
limits?: ResourceLimits;
|
|
48
|
+
}
|
|
49
|
+
export interface SandboxConfig {
|
|
50
|
+
provider: SandboxProvider;
|
|
51
|
+
workspace?: string | true;
|
|
52
|
+
mounts?: Mount[];
|
|
53
|
+
permissions?: Permissions;
|
|
54
|
+
env?: Record<string, string | (() => string)>;
|
|
55
|
+
limits?: ResourceLimits;
|
|
56
|
+
setup?: (sandbox: Sandbox) => Promise<void>;
|
|
57
|
+
persist?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface SandboxSnapshot {
|
|
60
|
+
/** Provider name that created this sandbox. */
|
|
61
|
+
provider: string;
|
|
62
|
+
/** Sandbox ID. */
|
|
63
|
+
id: string;
|
|
64
|
+
/** Workspace path. */
|
|
65
|
+
workspacePath: string;
|
|
66
|
+
/** Provider-specific state for restoration. */
|
|
67
|
+
state?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
export interface ExecOptions {
|
|
70
|
+
/** Working directory for the command. */
|
|
71
|
+
cwd?: string;
|
|
72
|
+
/** Additional environment variables. */
|
|
73
|
+
env?: Record<string, string>;
|
|
74
|
+
/** Timeout in milliseconds. */
|
|
75
|
+
timeout?: number;
|
|
76
|
+
/** Streaming output callback. Called for each chunk of stdout/stderr. */
|
|
77
|
+
onOutput?: (chunk: OutputChunk) => void;
|
|
78
|
+
}
|
|
79
|
+
export interface ExecResult {
|
|
80
|
+
/** Standard output. */
|
|
81
|
+
stdout: string;
|
|
82
|
+
/** Standard error. */
|
|
83
|
+
stderr: string;
|
|
84
|
+
/** Process exit code. */
|
|
85
|
+
exitCode: number;
|
|
86
|
+
}
|
|
87
|
+
export interface OutputChunk {
|
|
88
|
+
/** Which output stream this chunk came from. */
|
|
89
|
+
stream: "stdout" | "stderr";
|
|
90
|
+
/** The data content. */
|
|
91
|
+
data: string;
|
|
92
|
+
}
|
|
93
|
+
export interface Mount {
|
|
94
|
+
/** Host filesystem path. */
|
|
95
|
+
host: string;
|
|
96
|
+
/** Sandbox filesystem path. */
|
|
97
|
+
sandbox: string;
|
|
98
|
+
/** Mount mode. Default: "rw". */
|
|
99
|
+
mode?: "ro" | "rw";
|
|
100
|
+
}
|
|
101
|
+
export interface Permissions {
|
|
102
|
+
/** Filesystem access. Default: true. */
|
|
103
|
+
fs?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Network access. Default: false.
|
|
106
|
+
* - `false` — deny all (default)
|
|
107
|
+
* - `true` — allow all
|
|
108
|
+
* - `NetworkRule[]` — apply rules in order, first match wins, default deny
|
|
109
|
+
*/
|
|
110
|
+
net?: boolean | NetworkRule[];
|
|
111
|
+
/** Child process spawning. Default: true. */
|
|
112
|
+
childProcess?: boolean;
|
|
113
|
+
/** Inherit host environment variables. Default: false. */
|
|
114
|
+
inheritEnv?: boolean;
|
|
115
|
+
}
|
|
116
|
+
export interface ResourceLimits {
|
|
117
|
+
/** Memory limit in bytes. */
|
|
118
|
+
memory?: number;
|
|
119
|
+
/** CPU limit (fractional cores, e.g. 0.5). */
|
|
120
|
+
cpu?: number;
|
|
121
|
+
/** Global timeout in milliseconds. */
|
|
122
|
+
timeout?: number;
|
|
123
|
+
/** Disk limit in bytes. */
|
|
124
|
+
disk?: number;
|
|
125
|
+
/** Maximum concurrent processes. */
|
|
126
|
+
maxProcesses?: number;
|
|
127
|
+
}
|
|
128
|
+
export interface NetworkRule {
|
|
129
|
+
/** "allow" or "deny". Rules evaluated in order; first match wins. */
|
|
130
|
+
action: "allow" | "deny";
|
|
131
|
+
/** Domain pattern. Supports wildcards: "*.example.com", "api.github.com". */
|
|
132
|
+
domain?: string;
|
|
133
|
+
/** URL regex pattern. Matched against full URL. */
|
|
134
|
+
urlPattern?: string;
|
|
135
|
+
/** HTTP methods to match. Default: all. */
|
|
136
|
+
methods?: string[];
|
|
137
|
+
/** Port to match. */
|
|
138
|
+
port?: number;
|
|
139
|
+
}
|
|
140
|
+
export interface ProxiedRequest {
|
|
141
|
+
/** Full URL of the request. */
|
|
142
|
+
url: string;
|
|
143
|
+
/** HTTP method. */
|
|
144
|
+
method: string;
|
|
145
|
+
/** Target host. */
|
|
146
|
+
host: string;
|
|
147
|
+
/** Target port. */
|
|
148
|
+
port: number;
|
|
149
|
+
/** Unix timestamp (ms) when the request was made. */
|
|
150
|
+
timestamp: number;
|
|
151
|
+
/** Whether the request was blocked. */
|
|
152
|
+
blocked: boolean;
|
|
153
|
+
/** The rule that mat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;CACvB;AAID,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IAEzB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IAEZ,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IAEf,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IAEb,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IAEb,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IAEjB,qCAAqC;IACrC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentick/sandbox",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Sandbox primitive layer for Agentick — types, context, component, and pre-built tools",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent",
|
|
7
|
+
"ai",
|
|
8
|
+
"sandbox"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Ryan Lindgren",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/agenticklabs/agentick.git",
|
|
15
|
+
"directory": "packages/sandbox"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "src/index.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./src/index.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./testing": {
|
|
28
|
+
"types": "./src/testing.ts",
|
|
29
|
+
"import": "./dist/testing.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./testing": {
|
|
40
|
+
"types": "./dist/testing.d.ts",
|
|
41
|
+
"import": "./dist/testing.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"main": "./dist/index.js",
|
|
45
|
+
"types": "./dist/index.d.ts"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.build.json",
|
|
49
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit",
|
|
50
|
+
"lint": "oxlint src/",
|
|
51
|
+
"format:check": "oxfmt --check src/",
|
|
52
|
+
"clean": "rm -rf dist",
|
|
53
|
+
"dev": "tsc --watch"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@agentick/core": "workspace:*",
|
|
57
|
+
"react": "^19.0.0",
|
|
58
|
+
"zod": "^4.3.6"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/react": "^19.2.13",
|
|
62
|
+
"typescript": "^5.7.3",
|
|
63
|
+
"vitest": "^4.0.18"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentick/sandbox - Sandbox primitive layer
|
|
3
|
+
*
|
|
4
|
+
* Types, context, component, and pre-built tools for sandboxed execution.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ── Types ────────────────────────────────────────────────────────────────────
|
|
8
|
+
export type {
|
|
9
|
+
Sandbox as SandboxHandle,
|
|
10
|
+
SandboxProvider,
|
|
11
|
+
SandboxCreateOptions,
|
|
12
|
+
SandboxConfig,
|
|
13
|
+
SandboxSnapshot,
|
|
14
|
+
ExecOptions,
|
|
15
|
+
ExecResult,
|
|
16
|
+
OutputChunk,
|
|
17
|
+
Mount,
|
|
18
|
+
Permissions,
|
|
19
|
+
ResourceLimits,
|
|
20
|
+
NetworkRule,
|
|
21
|
+
ProxiedRequest,
|
|
22
|
+
} from "./types";
|
|
23
|
+
|
|
24
|
+
// ── Edit Types & Utilities ───────────────────────────────────────────────────
|
|
25
|
+
export { applyEdits, editFile, EditError } from "./edit";
|
|
26
|
+
export type { Edit, EditResult, EditChange } from "./edit";
|
|
27
|
+
|
|
28
|
+
// ── Context & Hook ───────────────────────────────────────────────────────────
|
|
29
|
+
export { SandboxContext, useSandbox } from "./context";
|
|
30
|
+
|
|
31
|
+
// ── Component ────────────────────────────────────────────────────────────────
|
|
32
|
+
export { Sandbox } from "./component";
|
|
33
|
+
export type { SandboxProps } from "./component";
|
|
34
|
+
|
|
35
|
+
// ── Tools ────────────────────────────────────────────────────────────────────
|
|
36
|
+
export { Shell, ReadFile, WriteFile, EditFile } from "./tools";
|
|
37
|
+
|
|
38
|
+
// ── Testing ──────────────────────────────────────────────────────────────────
|
|
39
|
+
// Import from "@agentick/sandbox/testing" — not re-exported here to avoid
|
|
40
|
+
// pulling vitest into production bundles.
|