The legacy Javascript sandbox runtime is now deprecated. This means that Forge can only create new apps on the latest runtime version. In addition:
If your app is running on the Javascript sandbox runtime, we strongly advise that you upgrade to the latest runtime.
This page describes the environment, features, and security of the legacy Javascript sandbox runtime version. This information is provided as a reference for developers who may still need it while upgrading to the latest runtime version. The latest runtime version offers the following advantages over the legacy runtime version:
The new native Node.js runtime requires the latest version of all Forge packages. Install updates for the packages your app uses, from the command line. For example:
1 2npm install -g @forge/cli@latest npm install @forge/api@latest
Repeat the npm install
command for any other Forge packages your app uses.
The runtime
section of the manifest.yml
file features a name
property that lets you specify what runtime to use. To specify the native sandbox runtime, set name
to sandbox
:
1 2app: runtime: name: sandbox
Adding the runtime.name
property to the manifest file will not trigger a major upgrade. As such, deploying this change alone to production will automatically install it on all sites.
When a Forge app is invoked, the legacy runtime executes its code within an app sandbox, which differs from a traditional Node.js environment.
You'll need to write your functions in a subset of Node.js. Some globals are not exposed, for example:
process
(except for process.env
)queueMicrotask
This means that some NPM packages that depend on these may not function correctly. The following Node.js built-in modules are not supported:
async_hooks
child_process
cluster
constants
dgram
dns
domain
http2
module
net
perf_hooks
readline
repl
sys
tls
trace_events
tty
v8
vm
worker_threads
Snapshot is the mechanism of evaluating your function's global scope at each deployment of the app, rather than at every invocation. Forge apps use snapshots by default, as this improves the response time for your app. You can disable snapshots, but this means your app needs to be fully evaluated on each invocation. For this reason, you should consider leaving snapshots enabled.
The following image highlights a sample snapshot context. Note that the invocation method is not run at this point in time.
The snapshots
flag is available under the runtime
object with a default value of true
.
1 2app: runtime: snapshots: true # Boolean
Environment variables are not available in the snapshot context.
1 2const myVariable = process.env.MY_VARIABLE; export const run = () => { console.log(myVariable) // Value is undefined };
Random values created at snapshot time are not random on each function invocation.
1 2const snapshotContextRandom = Math.random(); export const run = () => { console.log(snapshotContextRandom); // Same value per invocation };
We discourage using Buffers
in the snapshot context. If this is detected, warnings will be presented at deploy time.
1 2const snapshotContextBuffer = new Buffer(); // May result in unpredictable behavior export const run = () => { // ... };
The global process object is a partial implementation of the Node JS process.
1 2process
Key | Value |
---|---|
platform | forge |
env | See Environments. |
version | The underlying Node JS version. Example: process.version // 12.14.1
|
versions | Versions of runtime dependencies. Example: {
forge: 'forge:47',
node: '12.14.1'
}
|
nextTick | A polyfill of Node JS nextTick. |
Rate this page: