All posts

Agent security

My Coding Agent Installed a Malicious Package. How Do I Stop That?

Respond to a suspicious package install, then review registries, scripts, credentials and supported action controls with harmless fixtures.

Harden cover: Agent Package Installs. A right-column source to script to effect diagram illustrates the workflow. Conceptual editorial artwork; no measured result is depicted.

Executive summary

If a coding agent has installed a suspected malicious package, contain the affected environment and follow your incident process before continuing work. Then constrain future installations through approved registries, reviewed dependency changes, script policy, scoped credentials, and supported action checks. These controls have different boundaries. Our example uses a harmless local fixture to reason about installation; it does not ask readers to install a known malicious package or claim every package can be classified safely in advance.

Separate the incident from the prevention project

First determine what happened: package name and version, source registry, installation command, execution environment, credentials available, and subsequent activity. Preserve necessary evidence without copying secrets into a general-purpose ticket or chat.

If the package may have executed, do not assume that removing its directory reverses the effect. Coordinate isolation, credential review, recovery, and investigation with the responsible security and platform teams. The appropriate response depends on what authority the process had and what evidence is available.

Keep remediation ownership explicit. The developer may know the command, the platform team may own the runner image, and the identity team may control exposed tokens. An agent retrying the task should not independently decide that cleanup is complete.

Once the environment is handled, use the event to improve the install boundary. Avoid making an unverified incident narrative the basis for a universal prevention claim. Record confirmed facts and unresolved questions separately.

Understand when installation executes code

npm's scripts documentation describes lifecycle scripts and their execution behavior. Inspect the package manager and version actually used by the team. The effects of an installation include more than adding a package name to a manifest.

A dependency may run code during installation, become executable during tests, or execute when the application imports it. Restricting lifecycle scripts addresses one stage. It does not establish that later runtime behavior is safe.

Review direct and transitive dependencies, registry configuration, lockfile changes, and any newly introduced executable step. A familiar top-level package name does not describe every artifact resolved by the package manager. Preserve the resolved version and source in the review record so an investigator can distinguish the proposed dependency from what actually ran.

Use a harmless fixture to demonstrate the stage you want to control. For example, a local test package can write a synthetic marker when an install script runs. Keep the fixture isolated and free of network or credential access. Label its outcome as evidence about that configuration, not about malware detection.

Make the dependency proposal reviewable

Ask why the new package is needed, which existing capability it replaces or extends, and what authority it will receive. A task to fix a unit test may not require a new remote installer or a global package.

Keep the proposed manifest and lockfile diff visible. Inspect the resolved source and version, including redirects or registry changes where relevant. A dependency added under a plausible name can still arrive through an unintended source.

Assign an owner to approve exceptions. Some builds require installation scripts or native compilation. Define the allowed package, version, purpose, execution environment, and expiry of the exception rather than broadly re-enabling scripts across every agent session.

Do not use package popularity, age, or a clean scan as a guarantee. Those can inform review, but none independently establishes benign behavior. The operating decision should account for what the package can access if it behaves unexpectedly.

Constrain the installation environment

Run installation in an environment with only the resources needed for the build or test. Remove unrelated credentials and host mounts. Apply network and registry restrictions through the controls your environment supports.

Record which identity authenticates to the registry and whether installation can publish artifacts or alter configuration. Reading a private dependency and publishing a new release are different operations. A read task should not receive publishing authority by default.

Review cache behavior and reproducibility. A cached artifact can change what actually executes compared with the manifest alone. Preserve enough information to identify the installed bytes and relevant configuration when investigating an unexpected result.

Check alternate installers. Blocking one package-manager command leaves a gap if a helper can download and execute an arbitrary script through another route. Inventory the paths the agent can actually use and state which ones the control covers.

Test useful installs and prohibited changes

Create an acceptance exercise with an approved fixture dependency, a disallowed source, and a harmless script marker. Define the expected result for each case under the team's package policy.

Observe the proposed command, package-manager behavior, resulting files, and any process or network effects. A policy decision saying “blocked” should be correlated with what actually happened. An install failure caused by an unavailable registry does not establish that the intended security rule worked.

Include a legitimate build after tightening the controls. If an approved dependency requires a reviewed script, test the narrow exception and confirm that unrelated scripts remain constrained. Record both functionality and the security boundary.

Repeat relevant cases after changes to package-manager versions, registries, agent tools, base images, or dependency policy. Preserve the previous outcome so a change can be investigated rather than explained away as normal tool variation.

Add a supported pre-execution boundary

Harden evaluates supported proposed agent calls before they execute, using relevant task context and policy. An installation evaluation can ask whether a pending command fits the assignment and configured restrictions. Verify the actual integration and observe its decision and effect.

Do not describe that check as proof that every installed package is benign. A package can execute later, an independent process may sit outside the supported route, and the environment still needs its own containment and credentials policy.

Our package-installation guide provides the maintained control checklist. Bring a harmless allowed/prohibited pair to Control. If the environment mixes laptop, container, and CI installations, Book a Call with that route map rather than testing a live malicious package.

FAQs

Is deleting the dependency enough after a suspicious install?

Do not assume so. If code executed, review its available authority and subsequent effects through the incident process. Removing the package changes the current files; it does not establish that credentials, persistence, logs, or downstream systems were unaffected.

Does disabling install scripts make a package safe?

It constrains a particular execution stage when correctly configured. Package code may still run during tests, builds, imports, or later application execution. Verify the package-manager behavior and retain review, isolation, and least-privilege controls for those later stages.

Should agents be allowed to add dependencies at all?

Choose a reviewable process appropriate to the task. An agent can propose a dependency without receiving unrestricted installation or publishing authority. Approved sources, clear owners, and bounded exceptions let the team support legitimate work while keeping the consequential decisions explicit.

Can a lockfile prevent malicious behavior?

A lockfile helps identify resolved dependencies and supports reproducibility within the package manager's behavior. It does not prove those dependencies are benign. Review source, integrity information, scripts, and runtime authority, and inspect changes rather than treating the presence of a lockfile as approval.

How can we evaluate controls without real malware?

Use a local harmless fixture that creates a synthetic marker or attempts a controlled operation. Define the expected outcome and inspect actual effects. The result establishes behavior for that fixture and configuration; it is not a malware-detection benchmark or a guarantee about future packages.