Cloud Run (GCP)
Use the Google Cloud Run sandbox provider for ComputeSDK to run isolated commands and filesystem operations inside Cloud Run. Choose remote mode for a deployed gateway, or direct mode for in-container sandbox CLI control.
Install and set up the Cloud Run provider
The Cloud Run provider ships in the @computesdk/gcp package as the @computesdk/gcp/cloud-run subpath. The old @computesdk/cloud-run package is deprecated and re-exports the same provider.
The Google Cloud Run provider works in two modes:
Remote mode — connect to a deployed Cloud Run gateway service. Set both
CLOUD_RUN_SANDBOX_URLandCLOUD_RUN_SANDBOX_SECRET:
Direct mode — run your app inside a Cloud Run service deployed with
gcloud beta run deploy --sandbox-launcher, and the provider drives the in-containersandboxCLI (default/usr/local/gcp/bin/sandbox). Override the binary withCLOUD_RUN_SANDBOX_BINARY.
Remote mode is selected automatically when both sandboxUrl and sandboxSecret are set; otherwise the provider runs in direct mode.
Cloud Run supports two execution modes for sandbox sessions:
Ephemeral mode (default) —
create()creates a local logical handle only,runCommand()usessandbox do, anddestroy()removes local bookkeeping only.Stateful mode — set
executionMode: 'stateful'to havecreate()callsandbox run <id> --detach,runCommand()callsandbox exec <id>, anddestroy()callsandbox delete <id>.
create()
Local logical handle only
sandbox run <id> --detach
runCommand()
sandbox do -- /bin/sh -c <command>
sandbox exec <id> -- /bin/sh -c <command>
destroy()
Local bookkeeping only
sandbox delete <id>
filesystem
Per-operation sandbox do
Per-operation sandbox exec <id>
Use the Cloud Run provider
Sizes and lifecycle
sizeClass supports xs through xl by routing to a separate gateway service deployed at each CPU/RAM tier. Configure sizeGateways or CLOUD_RUN_SANDBOX_URL_XS, _SM, _MD, _LG, _XL; size-specific CLOUD_RUN_SANDBOX_SECRET_<SIZE> values can override the shared secret. Deploy each service with CLOUD_RUN_SIZE=<size> using the setup CLI. Create checks the gateway's advertised size; missing or mismatched configuration fails instead of using another tier. 2xl exceeds Cloud Run's 8-vCPU limit. See Sandbox sizes.
Create options executionMode and allowEgress override provider config. ephemeral: false selects a stateful sandbox (unless executionMode explicitly selects otherwise); snapshotId always restores statefully. The default remains ephemeral, so choose stateful mode for files/processes that must survive commands.
Remote gateways advertising snapshot support expose snapshot create/list/delete and repeated restores with snapshotId. Create the source with { ephemeral: false }. Snapshots capture the writable rootfs overlay, not memory, /tmp, or mounted paths; the source stays running. fork: true permits multiple independent restores, which restart the startup command rather than continuing running processes. There are no unified pause()/resume() hooks.
Gateway idle cleanup is separate from command timeout. Setup accepts CLOUD_RUN_SANDBOX_IDLE_TIMEOUT_MS; 0 disables idle cleanup, and a running command is not reaped as idle.
Cloud Run configuration options
Supported ComputeSDK operations
create
✅
Ephemeral mode creates a logical handle; stateful mode starts a detached sandbox with sandbox run.
getById
✅
Remote mode checks the gateway /v1/sandbox/info endpoint.
list
✅
Returns sandboxes tracked in-process.
destroy
✅
Ephemeral mode drops the handle; stateful mode deletes the detached sandbox.
runCommand
✅
Uses sandbox do in ephemeral mode and sandbox exec in stateful mode.
getInfo
✅
getUrl
❌
Throws — Cloud Run Sandboxes do not expose per-sandbox ports through the sandbox CLI.
filesystem
✅
Uses sandbox do in ephemeral mode and sandbox exec in stateful mode.
Cloud Run notes and limitations
Default command timeout is 300,000 ms (5 minutes).
Direct mode requires the service to be deployed with
gcloud beta run deploy --sandbox-launcher, or the sandbox binary check will fail.getUrlis not supported and throws for the requested port.
Last updated
Was this helpful?