Skip to content

Commit 64d0f28

Browse files
committed
feat: use @computesdk/secure-exec-nodejs, add probeCommand flag
Replace custom provider with the computesdk package import. Add per-provider probeCommand to override the default 'node -v' TTI probe.
1 parent 74b83ff commit 64d0f28

8 files changed

Lines changed: 42 additions & 69 deletions

File tree

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@computesdk/runloop": "^1.3.36",
4343
"@computesdk/sprites": "^0.1.1",
4444
"@computesdk/vercel": "^1.7.13",
45+
"@computesdk/secure-exec-nodejs": "file:../computesdk/packages/secure-exec-nodejs",
4546
"computesdk": "^2.2.1",
4647
"dotenv": "^17.2.1",
4748
"secure-exec": "0.1.1-rc.3"

src/benchmark.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function computeStats(values: number[], trimPercent: number = 0.05): Stat
2929
}
3030

3131
export async function runBenchmark(config: ProviderConfig): Promise<BenchmarkResult> {
32-
const { name, iterations = 100, timeout = 120_000, requiredEnvVars, sandboxOptions } = config;
32+
const { name, iterations = 100, timeout = 120_000, requiredEnvVars, sandboxOptions, probeCommand } = config;
3333

3434
// Check if all required credentials are available
3535
const missingVars = requiredEnvVars.filter(v => !process.env[v]);
@@ -52,7 +52,7 @@ export async function runBenchmark(config: ProviderConfig): Promise<BenchmarkRes
5252
console.log(` Iteration ${i + 1}/${iterations}...`);
5353

5454
try {
55-
const iterationResult = await runIteration(compute, timeout, sandboxOptions);
55+
const iterationResult = await runIteration(compute, timeout, sandboxOptions, probeCommand);
5656
results.push(iterationResult);
5757
console.log(` TTI: ${(iterationResult.ttiMs / 1000).toFixed(2)}s`);
5858
} catch (err) {
@@ -84,7 +84,7 @@ export async function runBenchmark(config: ProviderConfig): Promise<BenchmarkRes
8484
};
8585
}
8686

87-
export async function runIteration(compute: any, timeout: number, sandboxOptions?: Record<string, any>): Promise<TimingResult> {
87+
export async function runIteration(compute: any, timeout: number, sandboxOptions?: Record<string, any>, probeCommand?: string): Promise<TimingResult> {
8888
let sandbox: any = null;
8989

9090
try {
@@ -93,7 +93,7 @@ export async function runIteration(compute: any, timeout: number, sandboxOptions
9393
sandbox = await withTimeout(compute.sandbox.create(sandboxOptions), timeout, 'Sandbox creation timed out');
9494

9595
const result = await withTimeout(
96-
sandbox.runCommand('node -v'),
96+
sandbox.runCommand(probeCommand ?? 'node -v'),
9797
30_000,
9898
'First command execution timed out'
9999
) as { exitCode: number; stderr?: string };

src/concurrent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface ConcurrentConfig extends ProviderConfig {
66
}
77

88
export async function runConcurrentBenchmark(config: ConcurrentConfig): Promise<ConcurrentBenchmarkResult> {
9-
const { name, concurrency, timeout = 120_000, requiredEnvVars, sandboxOptions } = config;
9+
const { name, concurrency, timeout = 120_000, requiredEnvVars, sandboxOptions, probeCommand } = config;
1010

1111
// Check if all required credentials are available
1212
const missingVars = requiredEnvVars.filter(v => !process.env[v]);
@@ -32,7 +32,7 @@ export async function runConcurrentBenchmark(config: ConcurrentConfig): Promise<
3232

3333
// Fire all sandbox creations simultaneously — no awaiting between launches
3434
const promises = Array.from({ length: concurrency }, (_, i) =>
35-
runIteration(compute, timeout, sandboxOptions)
35+
runIteration(compute, timeout, sandboxOptions, probeCommand)
3636
.then(result => {
3737
console.log(` Sandbox ${i + 1}/${concurrency}: TTI ${(result.ttiMs / 1000).toFixed(2)}s`);
3838
return result;

src/custom-providers/secure-exec.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/providers.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { namespace } from '@computesdk/namespace';
1111
import { cloudflare } from '@computesdk/cloudflare';
1212
import { sprites } from '@computesdk/sprites';
1313
import { compute } from 'computesdk';
14-
import { secureExecProvider } from './custom-providers/secure-exec.js';
14+
import { secureExec } from '@computesdk/secure-exec-nodejs';
1515
import type { ProviderConfig } from './types.js';
1616

1717
/**
@@ -21,9 +21,13 @@ import type { ProviderConfig } from './types.js';
2121
* Automatic mode providers route through the ComputeSDK gateway (requires COMPUTESDK_API_KEY).
2222
*/
2323
export const providers: ProviderConfig[] = [
24-
// --- Custom providers ---
25-
secureExecProvider,
2624
// --- Direct mode (provider SDK packages) ---
25+
{
26+
name: 'secure-exec',
27+
requiredEnvVars: [],
28+
createCompute: () => secureExec(),
29+
probeCommand: 'module.exports = process.version;',
30+
},
2731
{
2832
name: 'e2b',
2933
requiredEnvVars: ['E2B_API_KEY'],

src/staggered.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface StaggeredConfig extends ProviderConfig {
77
}
88

99
export async function runStaggeredBenchmark(config: StaggeredConfig): Promise<StaggeredBenchmarkResult> {
10-
const { name, concurrency, staggerDelayMs, timeout = 120_000, requiredEnvVars, sandboxOptions } = config;
10+
const { name, concurrency, staggerDelayMs, timeout = 120_000, requiredEnvVars, sandboxOptions, probeCommand } = config;
1111

1212
// Check if all required credentials are available
1313
const missingVars = requiredEnvVars.filter(v => !process.env[v]);
@@ -38,7 +38,7 @@ export async function runStaggeredBenchmark(config: StaggeredConfig): Promise<St
3838
for (let i = 0; i < concurrency; i++) {
3939
const launchedAt = performance.now() - wallStart;
4040

41-
const p = runIteration(compute, timeout, sandboxOptions)
41+
const p = runIteration(compute, timeout, sandboxOptions, probeCommand)
4242
.then(result => {
4343
const readyAt = performance.now() - wallStart;
4444
rampProfile.push({ launchedAt, readyAt, ttiMs: result.ttiMs });

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface ProviderConfig {
1111
createCompute: () => any;
1212
/** Options passed to sandbox.create() (e.g. { image: 'node:20' }) */
1313
sandboxOptions?: Record<string, any>;
14+
/** Command to run as the TTI probe (default: 'node -v') */
15+
probeCommand?: string;
1416
}
1517

1618
export interface TimingResult {

0 commit comments

Comments
 (0)