Compute modules in Foundry operate under a "zero trust" security model, ensuring maximum isolation and security. By default, these modules lack any external network access, including access to other Foundry services. This strict isolation is crucial for maintaining a secure environment.
To enable external network access for your compute module, you must explicitly configure a source through the Data Connection application. Sources also allow secure storage of credentials needed to access external systems for use in your compute module. The following sections outline the process of using sources within your compute module as a means of packaging network policies and credentials.
Create a source in the Data Connection application, attaching any required network policies and secrets.
Ensure the following configurations:


In your compute module, select Configure > Sources > Add Sources.

When a compute module launches, source credentials are mounted as JSON in a file where the file path is contained by the SOURCE_CREDENTIALS environment variable. To access these credentials, perform the following:
SOURCE_CREDENTIALS environment variable.Some sources, like REST sources, require an additionalSecret prefix before the specified secret's name (for example, additionalSecretMySecretName).
Copied!1 2 3 4 5 6 7 8import json import os with open(os.environ['SOURCE_CREDENTIALS'], 'r') as f: credentials = json.load(f) # Access a specific secret (when using a REST source, secrets are prefixed with 'additionalSecret') secret = credentials["<Source API Name>"]["<Secret Name>"]
Copied!1 2 3 4const credentials = require(process.env.SOURCE_CREDENTIALS); // Access a specific secret (when using a REST source, secrets are prefixed with 'additionalSecret') const secret = credentials["<Source API Name>"]["<Secret Name>"];
You can also access source configuration details, including connection URLs, through the SOURCE_CONFIGURATIONS_PATH environment variable:
Copied!1 2 3 4 5 6 7 8 9import json import os with open(os.environ['SOURCE_CONFIGURATIONS_PATH'], 'r') as f: credentials = json.load(f) # Access a specific secret secrets = credentials["secrets"] url = credentials["httpConnectionConfig"]["url"]
Copied!1 2 3const credentials = require(process.env.SOURCE_CONFIGURATIONS_PATH); const url = credentials["httpConnectionConfig"]["url"];
You can use the compute module SDK ↗ to simplify this process. See the section below for details.
The compute module SDK ↗ provides a simplified interface for accessing sources and their credentials in Python. Instead of manually reading environment variables and parsing JSON, you can use the SDK to retrieve sources, secrets, and HTTPS connections directly.
To use the SDK, install the sources extra and import get_source from the compute_modules.sources_v2 module:
Copied!1pip install foundry-compute-modules[sources]
Then, pass the API name of your source:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14from compute_modules.sources_v2 import get_source from external_systems.sources import Source source: Source = get_source("<SOURCE_API_NAME>") # Retrieving a secret secret = source.get_secret("<SECRET_NAME>") # Making an HTTPS request https_connection = source.get_https_connection() client = https_connection.get_client() url = https_connection.url response = client.get(url).text
The get_source function returns a Source object that provides the following methods:
get_secret("<SECRET_NAME>"): Retrieves a specific secret by name from the source.get_https_connection(): Returns an HTTPS connection object configured with the source's network policies and credentials. Use get_client() on the connection to obtain an HTTP client and url to retrieve the base URL.To add or remove sources on your compute module, you must first stop the compute module. You cannot add or remove a source if the compute module is running. Additionally, changes to network policies on the source require a full restart of the compute module to apply. Changes to credentials will be reflected in a compute module rolling upgrade.