Deployment
Modal
Run serverless GPU and CPU tasks from Fabric sessions through Modal's native TypeScript SDK.
Fabric Harness runs its Node runtime in your application and sends sandbox work to a native Modal
Sandbox. The adapter never serializes the Modal client or its credentials into session history.
Install
pnpm add @fabric-harness/connectors modalConnect a sandbox
import { ModalClient } from 'modal';
import { modalSdkSandbox } from '@fabric-harness/connectors/modal';
const client = new ModalClient();
const app = await client.apps.fromName('fabric-harness', { createIfMissing: true });
const image = client.images.fromRegistry('node:22-alpine');
const remote = await client.sandboxes.create(app, image, {
timeoutMs: 300_000,
workdir: '/workspace',
// gpu: 'A10G',
// outboundDomainAllowlist: ['api.example.internal'],
});
const sandbox = modalSdkSandbox(remote, { cleanup: true });
try {
const fabric = await init({ sandbox });
const session = await fabric.session();
await session.prompt('Run the compute task and return the generated artifact.');
} finally {
await sandbox.cleanup();
client.close();
}modalSdkSandbox() supports streamed stdout/stderr, exact binary files, cwd/env, timeout and abort
settlement, portable sandboxId references, reconnect, and verified termination.
Reconnect after worker rotation
registerStandardSandboxRefDecoders({
modal: {
connect: ({ sandboxId }) => client.sandboxes.fromId(sandboxId!),
},
});Persist the result of session.sandboxRef({ portable: true }); it contains the sandbox ID and
Fabric capability metadata, never Modal tokens.
Environment variables
MODAL_TOKEN_ID: Modal token ID.MODAL_TOKEN_SECRET: Modal token secret.MODAL_APP_NAME: optional application name used by the runnable example.MODAL_IMAGE: optional container image used by the runnable example.
Run the credentialed contract with:
FABRIC_MODAL_TEST=1 MODAL_TOKEN_ID=... MODAL_TOKEN_SECRET=... \
pnpm --filter @fabric-harness/connectors test