@freestyle-sh/with-sandbox-agent 0.0.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/dist/index.d.ts +42 -0
- package/dist/index.js +119 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as freestyle_sandboxes from 'freestyle-sandboxes';
|
|
2
|
+
import { VmWith, VmWithInstance, VmSpec } from 'freestyle-sandboxes';
|
|
3
|
+
import { SandboxAgent } from 'sandbox-agent';
|
|
4
|
+
|
|
5
|
+
type KnownEnvKeys = "ANTHROPIC_API_KEY" | "OPENAI_API_KEY" | "AMP_API_KEY";
|
|
6
|
+
type EnvRecord = Partial<Record<KnownEnvKeys, string>> & Record<string, string>;
|
|
7
|
+
type VmSandboxAgentOptions = {
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
token?: string;
|
|
11
|
+
env?: EnvRecord;
|
|
12
|
+
};
|
|
13
|
+
type VmSandboxAgentResolvedOptions = {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
token?: string;
|
|
17
|
+
env: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
declare class VmSandboxAgent extends VmWith<VmSandboxAgentInstance> {
|
|
20
|
+
options: VmSandboxAgentResolvedOptions;
|
|
21
|
+
constructor(options?: VmSandboxAgentOptions);
|
|
22
|
+
configureSnapshotSpec(spec: VmSpec): VmSpec;
|
|
23
|
+
createInstance(): VmSandboxAgentInstance;
|
|
24
|
+
installServiceName(): string;
|
|
25
|
+
}
|
|
26
|
+
declare class VmSandboxAgentInstance extends VmWithInstance {
|
|
27
|
+
builder: VmSandboxAgent;
|
|
28
|
+
constructor(builder: VmSandboxAgent);
|
|
29
|
+
port(): number;
|
|
30
|
+
host(): string;
|
|
31
|
+
client({ domain }?: {
|
|
32
|
+
domain?: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
client: SandboxAgent;
|
|
35
|
+
domain: string;
|
|
36
|
+
}>;
|
|
37
|
+
/** @internal */
|
|
38
|
+
get _vm(): freestyle_sandboxes.Vm;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { VmSandboxAgent };
|
|
42
|
+
export type { VmSandboxAgentOptions, VmSandboxAgentResolvedOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { VmWith, VmSpec, VmWithInstance } from 'freestyle-sandboxes';
|
|
2
|
+
import { SandboxAgent } from 'sandbox-agent';
|
|
3
|
+
|
|
4
|
+
class VmSandboxAgent extends VmWith {
|
|
5
|
+
options;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super();
|
|
8
|
+
this.options = {
|
|
9
|
+
host: options?.host ?? "0.0.0.0",
|
|
10
|
+
port: options?.port ?? 2468,
|
|
11
|
+
token: options?.token,
|
|
12
|
+
env: options?.env ?? {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
configureSnapshotSpec(spec) {
|
|
16
|
+
const envExports = Object.entries(this.options.env).map(([k, v]) => `export ${k}="${v}"`).join("\n");
|
|
17
|
+
const tokenExport = this.options.token ? `export SANDBOX_TOKEN="${this.options.token}"` : "";
|
|
18
|
+
const tokenArg = this.options.token ? `--token "$SANDBOX_TOKEN"` : "--no-token";
|
|
19
|
+
return this.composeSpecs(
|
|
20
|
+
spec,
|
|
21
|
+
new VmSpec({
|
|
22
|
+
additionalFiles: {
|
|
23
|
+
"/opt/install-sandbox-agent.sh": {
|
|
24
|
+
content: `#!/bin/bash
|
|
25
|
+
set -e
|
|
26
|
+
export PATH="/root/.sandbox-agent/bin:$PATH"
|
|
27
|
+
curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh
|
|
28
|
+
`
|
|
29
|
+
},
|
|
30
|
+
"/opt/preinstall-agents.sh": {
|
|
31
|
+
content: `#!/bin/bash
|
|
32
|
+
set -e
|
|
33
|
+
export PATH="/root/.sandbox-agent/bin:$PATH"
|
|
34
|
+
sandbox-agent install-agent claude
|
|
35
|
+
sandbox-agent install-agent codex
|
|
36
|
+
sandbox-agent install-agent opencode
|
|
37
|
+
sandbox-agent install-agent amp
|
|
38
|
+
`
|
|
39
|
+
},
|
|
40
|
+
"/opt/run-sandbox-agent.sh": {
|
|
41
|
+
content: `#!/bin/bash
|
|
42
|
+
export PATH="/root/.sandbox-agent/bin:$PATH"
|
|
43
|
+
${tokenExport}
|
|
44
|
+
${envExports}
|
|
45
|
+
sandbox-agent server ${tokenArg} --host ${this.options.host} --port ${this.options.port}
|
|
46
|
+
`
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
systemd: {
|
|
50
|
+
services: [
|
|
51
|
+
{
|
|
52
|
+
name: "install-sandbox-agent",
|
|
53
|
+
mode: "oneshot",
|
|
54
|
+
exec: ["bash /opt/install-sandbox-agent.sh"],
|
|
55
|
+
timeoutSec: 300
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "preinstall-agents",
|
|
59
|
+
mode: "oneshot",
|
|
60
|
+
after: ["install-sandbox-agent.service"],
|
|
61
|
+
requires: ["install-sandbox-agent.service"],
|
|
62
|
+
exec: ["bash /opt/preinstall-agents.sh"],
|
|
63
|
+
timeoutSec: 600
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "sandbox-agent",
|
|
67
|
+
mode: "service",
|
|
68
|
+
after: ["preinstall-agents.service"],
|
|
69
|
+
requires: ["preinstall-agents.service"],
|
|
70
|
+
restartPolicy: {
|
|
71
|
+
policy: "always"
|
|
72
|
+
},
|
|
73
|
+
exec: ["bash /opt/run-sandbox-agent.sh"]
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
createInstance() {
|
|
81
|
+
return new VmSandboxAgentInstance(this);
|
|
82
|
+
}
|
|
83
|
+
installServiceName() {
|
|
84
|
+
return "install-sandbox-agent.service";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
class VmSandboxAgentInstance extends VmWithInstance {
|
|
88
|
+
builder;
|
|
89
|
+
constructor(builder) {
|
|
90
|
+
super();
|
|
91
|
+
this.builder = builder;
|
|
92
|
+
}
|
|
93
|
+
port() {
|
|
94
|
+
return this.builder.options.port;
|
|
95
|
+
}
|
|
96
|
+
host() {
|
|
97
|
+
return this.builder.options.host;
|
|
98
|
+
}
|
|
99
|
+
async client({ domain } = {}) {
|
|
100
|
+
const resolvedDomain = domain ?? `${crypto.randomUUID()}-sandbox-agent.style.dev`;
|
|
101
|
+
const freestyle = this._vm._freestyle;
|
|
102
|
+
await freestyle.domains.mappings.create({
|
|
103
|
+
domain: resolvedDomain,
|
|
104
|
+
vmId: this.vm.vmId,
|
|
105
|
+
vmPort: this.port()
|
|
106
|
+
});
|
|
107
|
+
const client = await SandboxAgent.connect({
|
|
108
|
+
baseUrl: `https://${resolvedDomain}`,
|
|
109
|
+
token: this.builder.options.token
|
|
110
|
+
});
|
|
111
|
+
return { client, domain: resolvedDomain };
|
|
112
|
+
}
|
|
113
|
+
/** @internal */
|
|
114
|
+
get _vm() {
|
|
115
|
+
return this.vm;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { VmSandboxAgent };
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@freestyle-sh/with-sandbox-agent",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"freestyle-sandboxes": "^0.1.14",
|
|
7
|
+
"sandbox-agent": "^0.1.3"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/node": "^22.0.0",
|
|
11
|
+
"pkgroll": "^2.11.2",
|
|
12
|
+
"typescript": "^5.8.3"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"source": "./src/index.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "pkgroll"
|
|
29
|
+
}
|
|
30
|
+
}
|