Skip to content
GitHub

Railway

Deploy sandboxes on Railway with ComputeSDK

Section titled “Deploy sandboxes on Railway with ComputeSDK”

Deploy and manage containerized sandboxes on Railway’s infrastructure with ComputeSDK.


Railway is an infrastructure platform with instant deployments and automatic SSL. With ComputeSDK’s Railway provider, you can self-host your own sandbox execution environment.


Prerequisites:


Before using Railway as a sandbox provider, you need to deploy the ComputeSDK sandbox infrastructure to your Railway account. This only needs to be done once.

Deploy to Railway

What this deploys:

The template deploys a lightweight binary (computesdk/compute) that converts Railway’s infrastructure into a sandbox provider. It handles:

  • Sandbox lifecycle management
  • Code execution
  • File system operations
  • Resource isolation

Click the button above or visit railway.com/deploy/sandbox and click “Deploy Now” to create the project.

Note: This will deploy a sample sandbox (referred to as a “service” in Railway). Subsequent sandboxes you create using ComputeSDK will be deployed within this same project. You can safely delete the sample sandbox after deployment.


Once you’ve deployed the template, collect these three values:

API Token

  1. Go to your Railway workspace settings
  2. Navigate to Tokens
  3. Create a “New Token”
  4. Name it (e.g., “ComputeSDK Integration”) and copy the generated token

Project ID

  1. Open your Railway project
  2. Go to Settings
  3. Copy the Project ID from the Project Info section

Environment ID

Find it in the URL when viewing your project settings:

https://railway.com/project/{PROJECT_ID}/settings?environmentId=={ENVIRONMENT_ID}

Note: The sandbox ID returned by ComputeSDK is different from the service name shown in the Railway dashboard. The service name in Railway is the name of the deployed service, while the sandbox ID is the unique identifier for the sandbox instance running inside the service.



Install the ComputeSDK package in your application:

npm install computesdk

Add your credentials to a .env file:

# ComputeSDK credentials
COMPUTESDK_API_KEY=your_computesdk_api_key

# Railway credentials
RAILWAY_API_KEY=your_railway_api_key
RAILWAY_PROJECT_ID=your_railway_project_id
RAILWAY_ENVIRONMENT_ID=your_railway_environment_id

See Getting your Railway credentials for how to obtain these values.


ComputeSDK auto-detects Railway as your provider from the environment variables:

import { compute } from 'computesdk';

// Create a new sandbox
const sandbox = await compute.sandbox.create();
console.log(`Sandbox created: ${sandbox.sandboxId}`);

// Get sandbox info
const info = await sandbox.getInfo();
console.log(`Sandbox status: ${info.status}`);

// Clean up when done
await sandbox.destroy();

Your sandboxes are now running on your self-hosted Railway infrastructure!


Explicit provider configuration (optional)

Section titled “Explicit provider configuration (optional)”

If you prefer to configure the provider programmatically—useful for multi-provider setups or dynamic configuration—pass credentials directly:

import { compute } from 'computesdk';

compute.setConfig({
   computesdkApiKey: process.env.COMPUTESDK_API_KEY,
   provider: 'railway',
   railway: {
     apiToken: process.env.RAILWAY_API_KEY,
     projectId: process.env.RAILWAY_PROJECT_ID,
     environmentId: process.env.RAILWAY_ENVIRONMENT_ID
   }
});

const sandbox = await compute.sandbox.create();

The Railway provider accepts the following configuration options:

OptionEnvironment VariableRequiredDescription
apiTokenRAILWAY_API_KEYYesYour Railway API token
projectIdRAILWAY_PROJECT_IDYesThe project ID where you deployed the sandbox template
environmentIdRAILWAY_ENVIRONMENT_IDYesThe target environment within the project
interface RailwayConfig {
  /** Railway API token - if not provided, uses RAILWAY_API_KEY env var */
  apiToken?: string;
  /** Railway Project ID - if not provided, uses RAILWAY_PROJECT_ID env var */
  projectId?: string;
  /** Railway Environment ID - if not provided, uses RAILWAY_ENVIRONMENT_ID env var */
  environmentId?: string;
}