Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Troubleshooting Node.js Apps
      • Working with Node.js
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Vector Database
    • Working with AI
    • Heroku Inference
      • AI Models
      • Inference Essentials
      • Inference API
      • Quick Start Guides
    • Model Context Protocol
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Heroku Architecture
  • Compute (Dynos)
  • Dyno Management
  • Working with One-Off Dynos

Working with One-Off Dynos

Last updated April 11, 2025

Table of Contents

  • Run a One-Off Dyno
  • Execution Syntax
  • Shield Private Spaces
  • Run Tasks in the Background
  • Stop a One-Off Dyno
  • Run Tasks Inside an Existing Dyno
  • Examples
  • Additional Reading

One-off dynos allow you to perform administrative or maintenance tasks for your app and are helpful for debugging. This article explains how to work with them. To learn about their concepts, see One-Off-Dynos.

heroku run, which runs interactive one-off dynos, is unavailable in Fir. Fir-generation apps can use heroku run:detached to run tasks in the background in a one-off dyno, or `heroku run:inside to run tasks inside an existing running dyno. Subscribe to the changelog to learn when we add heroku run for Fir.

 

Any time spent executing a one-off dyno contributes to usage and we charge for it just like any other dyno.

Run a One-Off Dyno

You can start a one-off dyno with the Heroku Dashboard, CLI or API.

With the Heroku Dashboard

In the dashboard, click the app you want to run a one-off dyno in. Click the More button in the upper right of the app’s Overview page. Click Run console. Enter the command to run in the dyno. See Execution Syntax for help.

With the CLI

Execute heroku run <command>. See Execution Syntax for help.

With the API

Use the Dyno Create API call. Pass run as the process type parameter and the command run in the dyno to the command parameter. See Execution Syntax for help.

Execution Syntax

heroku run takes two types of parameters. You can either supply the command to execute, or a process type that is present in your application’s Procfile.

If you supply a command, either a script or other executable available to your application, then it executes as a one-off dyno, together with any additional arguments. For example, to execute the Python interpreter with a file dowork.py supplied as an argument, execute heroku run python dowork.py.

If you instead supply a process type, as declared in a Procfile, then its definition gets substituted and executed together with any additional arguments. For example, given the following Procfile:

myworker:  python dowork.py

Executing heroku run myworker 42 runs python dowork.py 42 as a one-off dyno.

Handling Flags

Separate any commands or flags that must be run on the dyno from the heroku command and flags with a --.

For example, to run ls -a on a dyno:

$ heroku run --app example-app -- ls -a
Running ls -a on ⬢ forker... up, run.4520 (Eco)
.       ..        Procfile               server.js

Shield Private Spaces

To use one-off dynos for apps in Shield Private Spaces, you must first add an SSH key to your user account. See Managing SSH Keys for more info.

Run Tasks in the Background

In the Common Runtime, we expand the values of the config vars referenced in your scripts before sending the output to your logs for audit purposes. Avoid using direct references to sensitive environment variables.

Fir-generation apps must have at least one deploy and one process type defined in their Procfile to start a detached one-off dyno.

You can run a dyno in the background using heroku run:detached. Unlike heroku run, these dynos send their output to your logs instead of your console window. You can use heroku logs to view the output from these commands:

$ heroku run:detached rake db:migrate
Running rake db:migrate... up, run.2
Use 'heroku logs --dyno run.2' to view the log output.

Stop a One-Off Dyno

Check your current running dyno’s name using heroku ps:

$ heroku ps
=== run: one-off processes
run.4520: starting 2013/03/13 15:38:08 (~ 1s ago): `bash`

=== web: `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web.1: up 2013/03/13 15:08:07 (~ 30m ago)
web.2: up 2013/03/12 17:06:09 (~ 22h ago)

To stop a running one-off dyno, use heroku ps:stop with its name.

$ heroku ps:stop run.4520
Stopping run.4520 process... done

One-off dynos don’t stop when you issue heroku ps:restart on your application. They also don’t restart after a new app release.

Run Tasks Inside an Existing Dyno

Cedar-Generation Apps

While one-off dynos are a great fit for administrative tasks, sometimes you need to debug a service on a production dyno. Unlike one-off dynos, Heroku Exec makes an SSH connection directly to an existing dyno (e.g., web.2). Exec also allows you to copy files off of a dyno, forward traffic on a local port to a dyno, and take advantage of common Java debugging tools. Heroku Exec is only available for Cedar-generation apps.

Fir-Generation Apps

To run tasks inside an existing dyno for a Fir-generation app, use heroku run:inside. See Run Tasks In an Existing Dyno for details.

Examples

Bash

To see one-off dynos in action, execute the bash command, available in all applications deployed to Heroku:

$ heroku run bash
Running bash attached to terminal... up, run.1
~ $

At this point you have a one-off dyno executing the bash command which provides a shell environment for exploring the file system and process environment.

Interact with the shell and list all the files that you deployed:

~ $ ls
Procfile project.clj src bin ...

If you had a batch file in the bin directory, you can simply execute it, just as you can many other Unix commands:

~ $ echo "Hi there"
Hi there
~ $ pwd
/app
~ $ bin/do-work

Remove a few files, and exit:

~ $ rm Procfile project.clj
~ $ exit

Because each dyno has its own ephemeral filesystem, the deleted files won’t change your running application.

Database Migration

Here’s an example database migration:

$ heroku run rake db:migrate
(in /app)
Migrating to CreateWidgets (20110204210157)
==  CreateWidgets: migrating ==================================================
-- create_table(:widgets)
   -> 0.0497s
==  CreateWidgets: migrated (0.0498s) =========================================

Run a Console

Here’s an example of running a rails console:

$ heroku run rails console
Running rails console attached to terminal... up, run.2
Loading production environment (Rails 3.0.3)
irb(main):001:0> Widget.create :name => 'Test'
=> #<Widget id: 1, name: "Test", size: nil, created_at: "2011-05-31 02:37:51", updated_at: "2011-05-31 02:37:51">

Additional Reading

  • One-Off Dynos
  • Heroku Scheduler
  • Heroku Exec

Keep reading

  • Dyno Management

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices