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:
- A ComputeSDK account with an API key
- A Railway account with the ComputeSDK sandbox template deployed
- Node.js 18+ installed
Deploying the Railway sandbox template
Section titled “Deploying the Railway sandbox template”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.
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.
Getting your Railway credentials
Section titled “Getting your Railway credentials”Once you’ve deployed the template, collect these three values:
API Token
- Go to your Railway workspace settings
- Navigate to Tokens
- Create a “New Token”
- Name it (e.g., “ComputeSDK Integration”) and copy the generated token
Project ID
- Open your Railway project
- Go to Settings
- 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.
Using ComputeSDK with Railway
Section titled “Using ComputeSDK with Railway”Step 1: Install ComputeSDK
Section titled “Step 1: Install ComputeSDK”Install the ComputeSDK package in your application:
npm install computesdkStep 2: Configure environment variables
Section titled “Step 2: Configure environment variables”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_idSee Getting your Railway credentials for how to obtain these values.
Step 3: Create and manage sandboxes
Section titled “Step 3: Create and manage sandboxes”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();Configuration reference
Section titled “Configuration reference”The Railway provider accepts the following configuration options:
| Option | Environment Variable | Required | Description |
|---|---|---|---|
apiToken | RAILWAY_API_KEY | Yes | Your Railway API token |
projectId | RAILWAY_PROJECT_ID | Yes | The project ID where you deployed the sandbox template |
environmentId | RAILWAY_ENVIRONMENT_ID | Yes | The 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;
}Next steps
Section titled “Next steps”- Learn about sandbox lifecycle management
- Explore Sandbox methods
- View the @computesdk/railway package