Benchmarked
Cloud Run
Last updated
Was this helpful?
Was this helpful?
npm install @computesdk/cloud-runCLOUD_RUN_SANDBOX_URL=https://your-gateway-xyz.run.app
CLOUD_RUN_SANDBOX_SECRET=your_shared_secret
# Optional: Google-signed identity token for IAM-authenticated services
CLOUD_RUN_AUTH_TOKEN=your_identity_tokenimport { cloudRun } from '@computesdk/cloud-run';
const compute = cloudRun({
sandboxUrl: process.env.CLOUD_RUN_SANDBOX_URL,
sandboxSecret: process.env.CLOUD_RUN_SANDBOX_SECRET,
});
// Create sandbox
const sandbox = await compute.sandbox.create();
// Run a command
const result = await sandbox.runCommand('echo "Hello from Cloud Run!"');
console.log(result.stdout); // "Hello from Cloud Run!"
// Clean up
await sandbox.destroy();interface CloudRunConfig {
/** URL of the deployed Cloud Run gateway service for remote mode. */
sandboxUrl?: string;
/** Shared bearer token for the deployed Cloud Run gateway service. */
sandboxSecret?: string;
/** Optional Google-signed identity token for Cloud Run services that require IAM auth. */
gatewayAuthToken?: string;
/** Execution mode. Ephemeral uses `sandbox do`; stateful uses `sandbox run`, `exec`, and `delete`. Defaults to ephemeral. */
executionMode?: 'ephemeral' | 'stateful';
/** Path to the Cloud Run sandbox binary. Defaults to CLOUD_RUN_SANDBOX_BINARY or /usr/local/gcp/bin/sandbox. */
sandboxBinary?: string;
/** Sandbox CLI mode. Cloud Run's CLI defaults this to local. */
mode?: 'local' | 'container';
/** Allow network egress from sandboxed commands. GCP service account access remains blocked by Cloud Run. */
allowEgress?: boolean;
/** Root filesystem to expose to sandboxes. Defaults to /. */
rootfs?: string;
/** Working directory for sandboxed commands or newly-created stateful sessions. */
workdir?: string;
/** Container template name for Cloud Run multi-container services. */
template?: string;
/** Writable persistent host path shared across executions. */
persistDir?: string;
/** Writable overlay directory. Caller is responsible for cleanup. */
overlayDir?: string;
/** Allow mounted filesystems to be writable. */
write?: boolean;
/** Bind mounts to attach to the sandbox. */
mounts?: CloudRunMount[];
/** Environment variables applied to sandboxed commands or newly-created stateful sessions. */
env?: Record<string, string>;
/** Extra args passed before the sandbox subcommand, e.g. global debug flags. */
globalArgs?: string[];
/** Extra args passed to `sandbox do` and `sandbox run`. */
runArgs?: string[];
/** Extra args passed to `sandbox exec` in stateful mode. */
execArgs?: string[];
}
interface CloudRunMount {
type?: 'bind';
src: string;
dst: string;
}