Deep-dive on the Next Gen Platform. Join the Webinar!

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
      • Working with Node.js
      • Node.js Behavior in Heroku
      • Troubleshooting Node.js Apps
    • 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
    • Working with AI
  • 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
  • Run Tasks in An Existing Dyno

Run Tasks in An Existing Dyno

Last updated April 10, 2025

Table of Contents

  • Using heroku run:inside
  • Disconnect From a Dyno
  • Timeout
  • Examples
  • Additional Reading

The heroku run:inside command is only available for Fir-generation apps. Cedar-generation apps can use heroku ps:exec.

 

The heroku run command, which spins up one-off-dynos, is unavailable for Fir-generation apps. Use heroku run:inside until we make heroku run available for Fir. See Heroku Generations for more info.

The heroku run:inside command allows you to connect over SSH to one of your app’s existing dynos and run commands inside of it.

Some use cases for heroku run:inside are:

  • Accessing an app’s console
  • Debugging production services

For database migrations, use heroku run or heroku run:detached instead.

Using heroku run:inside

Pre-requisites

  • Install the Heroku CLI.
  • Ensure you have added an SSH key to your Heroku account.
  • Have at least one running dyno to run your command in.

You can check which dynos are currently running in your application with heroku ps.

$ heroku ps
=== web: `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web-5f454b8b9-ztwlh: up 2024/11/01 18:04:16 +0000 (~ 19h ago)

Execution Syntax

heroku run:inside accepts two arguments: the name of the dyno you want to connect to, and the command to execute inside that dyno.

$ heroku run:inside <example-dyno-name> <example-command>

Heroku automatically prepends the command to execute inside the dyno with launcher before executing it. To prevent this prepend, pass in the --no-launcher flag.

If you get an unexpected error when trying to run a command, try the command again while passing in the --no-launcher flag.

For the second argument, heroku run:inside can also accept a process type that is present in your application’s Procfile.

For example, to execute the Python interpreter with a file dowork.py supplied as an argument, execute heroku run:inside <example-dyno-name> python dowork.py.

You can also supply a process type declared in a Procfile. In this case its definition gets substituted and executed together with any additional arguments. For example, given the following Procfile:

myworker: python dowork.py

You can run python dowork.py 42 inside the <example-dyno-name> dyno by executing:

heroku run:inside <example-dyno-name> myworker 42

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:inside web-5f454b8b9-ztwlh --app your-app -- ls -a
Running ls -a on ⬢ your-app... up, web-5f454b8b9-ztwlh
.       ..        Procfile               server.js

Disconnect From a Dyno

To disconnect from a dyno you connected to with heroku run:inside, type exit. The dyno continues to run as usual after you exit.

$ heroku run:inside web-5f454b8b9-ztwlh bash
Running bash on your-app... up, web-5f454b8b9-ztwlh
~ $ bin/do-work
~ $ exit
$

Timeout

A session times out on its own if there’s no interaction for 15 minutes.

Examples

Bash

To see an existing dyno in action, execute the bash command, available in all applications deployed to Heroku:

$ heroku run:inside web-5f454b8b9-ztwlh bash
Running bash on your-app... up, web-5f454b8b9-ztwlh
~ $

The bash command provides a shell environment for exploring the file system and process environment of your existing web-5f454b8b9-ztwlh dyno. Interact with the shell and list all the files that you deployed:

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

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

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

To exit:

~ $ exit

Run a Console

Run an app console:

$ heroku run:inside web-5f454b8b9-ztwlh rails console
Running rails console on your-app... up, web-5f454b8b9-ztwlh
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
  • Working with One-Off Dynos
  • Heroku Exec

Keep reading

  • Dyno Management

Feedback

Log in to submit feedback.

Working with One-Off Dynos Scaling Your Dyno Formation

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